我需要计算一个供应作为标准输入的C程序中评论中的字符数。 这是我的函数,但由于某些原因它没有正确地计数。 你能帮我吗?
int characters(FILE *file)
{
int i=0;
char ch[500], *p;
while (fgets(ch, sizeof(ch),file)!=NULL)
{
p=ch;
while (*p)
{
if (*p=='/')
{
p++;
if (*p=='*')
{
p++;
while (*p!='*' && *(p++)!='/')
{
i++;
p++;
}
}
}
else
p++;
}
return i;
}