<分区>
所以我正在尝试编写一个代码来删除给定代码中的所有注释。 当给我的代码一个条件来检查当前字符是否为“*”而下一个字符是否为“/”(注释结束)并尝试运行它时,它接受 ./作为 */。
代码看起来像这样:
char line[MAX_LINE_LEN] = { 0 };
...Input and some code...
for (int index = 0; index < MAX_LINE_LEN - 1 && line[index] != '\0';
index++)
{
if (line[index] == '/' && line[index + 1] == '/'
&& comment_nest == 0)
break;
if (line[index == '/'] && line[index + 1] == '*')
comment_nest++;
if (line[index == '*'] && line[index + 1] == '/')
comment_nest--;
if (comment_nest == 0)
cout << line[index];
}
所以当输入包含 ./时,我不断收到“comment_nest--”
如有任何帮助,我们将不胜感激。 谢谢。