I need to write a program that can remove comments from a file. Removing standard comments is quite simple. However, I haven't been able to come up with a way to remove a "hyphenated" comment. For example, the first two lines of code are comments. My program does not understand this and removes only the first line of the comment.
// Function for output to console\
ns2
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iso646.h>
int main() {
FILE *in = fopen("inp.c", "r");
FILE *out = fopen("out.c", "w");
char ch;
while ((ch = fgetc(in)) not_eq EOF) {
if (ch == '/') {
int flag_1 = 0;
ch = fgetc(in);
if (ch == '/') {
flag_1 = 1;
while ((ch = fgetc(in)) not_eq '\n') {
ch = fgetc(in);
if (ch == '\\') {
ch = '\n';
break;
}
}
ch = '\n';
}
else if (ch == '*') {
flag_1 = 1;
while ((ch = fgetc(in)) not_eq EOF) {
if ((ch = fgetc(in)) == '*' and (ch = fgetc(in)) == '/') {
ch = '\n';
break;
}
}
}
if (flag_1 == 0)
fputc('/', out);
}
if (ch == '"') {
fputc(ch, out);
while ((ch = fgetc(in)) not_eq '"') {
fputc(ch, out);
}
}
fputc(ch, out);
}
fclose(in);
fclose(out);
return 0;
}
I have been trying to supplement / change the program for more than an hour, but the knowledge of a beginner does not allow me to master this task. I will be glad to your advice!