易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++ 学习笔记[03].去掉C风格的注释

网上搜索了一大堆去掉/*和*/之间注释的代码,就像<The C Programming Language>练习1-23里有人说的一样
大部分都会被以下的程序broken,这个功能看起来简单,实际上很有难度.网上实现的代码,除了我找到的一个用文件指针实现的没有问题外,其余的都存在各种bug,不信的话就用以下的程序测试一下:-),当然这个程序也不够完善.
还是有限状态自动机实现起来更严谨也容易理解得多:
/* krx123tp.c - a test program to serve as input to krx123*.c
*
* This is a shameless copy of Ben Pfaff's solution, to which I have
* added a few extra statements to further test the candidate programs
* for this exercise. As Ben says, this program already contains lots
* of examples of comments and not-quite-comments. I've just made it
* a little tougher.
*
*/
/* K&R2 1-23: Write a program to remove all comments from a C program.
Don't forget to handle quoted strings and character constants
properly. C comments do not nest.
This solution does not deal with other special cases, such as
trigraphs, line continuation with \, or <> quoting on #include,
since these aren't mentioned up 'til then in K&R2. Perhaps this is
cheating.
Note that this program contains both comments and quoted strings of
text that looks like comments, so running it on itself is a
reasonable test. It also contains examples of a comment that ends
in a star and a comment preceded by a slash. Note that the latter
will break C99 compilers and C89 compilers with // comment
extensions.
Interface: The C source file is read from stdin and the
comment-less output is written to stdout. **/
#include <stdio.h>
int
main(void)
{
/* State machine's current state. */
enum {
PROGRAM,
SLASH,
COMMENT,
STAR,
QUOTE,
LITERAL
} state;
/* If state == QUOTE, then ' or ". Otherwise, undefined. */
int quote;
state = PROGRAM;
for (;;) {
int c = getchar();
if (c == EOF)


相关文档:

C\C++ byte或者char数组转int值

假设有char a[2];
如要把a转换为int值。应是如下写法int b=*(int *)a;
即,先把指针a 转换为一个int指针,然后再此基础上取值。
但是另一种写法 int b=(int)(*a);是不对的,*a 取a的内存单元内容,因为现在a是char指针,所以只会取a[1]中内容,最大为255. 这里要说明的是,在把char或byte数组转换为其他类型的值时,要先 ......

C++ 之Boost学习笔记 Linux下编程

C++学习笔记--Linux下编程
一、关于Boost的使用,几种常用方法,只是自己工作、学习中总结的,有些方法的确有些繁琐,能满足需求,应该还有更加简单快捷的方式,待改进。
1、判断字符串与正则表达式是否匹配(完全匹配)
bool IsMatch(const char* data,const char * regx)
{
    boost::regex express ......

C程序员的情书

#include <stdio.h>
#include <string.h>
int
main(void)
{
char str[] =
"3BVPSq4xF.K?=u#,"
"G'K<MrDnRr7gH%#,"
"XKf<f%G`w^=?C<#,"
"HgU_AnNR?*PDQU#,"
......

使用C语言扩展Python(三)

上一篇中我们已经了解如何在Python程序和C模块之间进行值的相互传递,现在我们来进入实作阶段,看看如何将一个C语言开发的开源mp3编解码库LAME包装为一个Python下可以使用的扩展模块。首先去http://lame.sourceforge.net/download.php下载LAME的源代码,然后切换到root用户编译源代码,./configure
make
make instal ......

简述C和C++程序员学习历程

哈哈!有幸在某网站发现这篇文章,读罢,觉得蛮有道理,发来大家一起共勉之    
总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。 
' J$ |0 ?! p% w" t5 D6 D: c9 |0 B
  一家之言,欢迎拍砖哈。 
  1、可以考虑先学习C. 
/ U$ X+ X/ P; Y ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号