编写一个删除C语言程序中所有注释语句!
#include<stdio.h>
void rcomment(int c);
void in_comment(void);
void echo_quote(int c);
void main()
{
int c, d;
while ((c = getchar()) != EOF)
rcomment(c);
return 0;
}
void rcomment(int c)
{
int d;
if (c == '/')
if ((d = getchar()) == '*')
in_comment();
else if (d == '/')
{
putchar(c);
rcomment(d);
}
else
{
putchar(c);
putchar(d);
}
else if (c == '\'' || c == '"')
echo_quote(c);
else
putchar(c);
}
void in_comment(void)
{
int c, d;
c = getchar();
d = getchar();
while (c != '*' || d != '/')
{
c = d;
d = getchar();
}
}
/* 谁能给我解释一下这个函数有什么作用?我觉得没有它也没有什么关系 */
void echo_quote(int c)
{
int d;
putchar(c);
while ((d = getchar()) != c)
{
putchar(d);
if (d == '\\')
putchar(getchar());
}
putchar(d);
}
谁能给我解释一下echo_quote这个函数有什么作用?我觉得没有它也没有什么关系.