write a C programing to modify program to ignore any comments that begin with //
时间: 2024-05-09 15:16:54 浏览: 81
linux_programing.rar_Linux/Unix编程_Unix_Linux_
Sure, here's a modified version of a C program that ignores comments beginning with "//":
```c
#include <stdio.h>
int main() {
int c, last_c = 0;
while ((c = getchar()) != EOF) {
if (last_c == '/' && c == '/') {
// Skip the rest of the line
while ((c = getchar()) != EOF && c != '\n');
} else {
putchar(c);
}
last_c = c;
}
return 0;
}
```
If the program encounters two consecutive slashes "//" it will skip the rest of the line, effectively ignoring any comment.
阅读全文