Can someone please examine my code here. The program is supposed to remove all comments from a C program. So far it only checks for // comments. I'm feeding it it's own source as the input. For some reason it doesn't work however. When I run the program cygwin just gets stuck in an infinite loop (at least I think). Could someone please tell me what the problem is?
Code:#include <stdio.h>
#define MAXLENGTH 1000
int Getline(char str[]);
int main(void) {
char line[MAXLENGTH];
while(Getline(line) != 0)
printf("%s\n", line);
return 0;
}
int Getline(char str[]) {
int i;
int c;
int linestart; // linestart = index of start of // comment, linecomment = boolean of whether the previous character was a /
int linecomment;
for(i = 0; ((c = getchar()) != '\n') && (i < MAXLENGTH); i++) {
linecomment = 0;
if(i == EOF)
return 0;
if(c == '/')
linecomment = 1;
else if(linecomment && c == '/'){
str[i-1] = '\0';
return 0;
}
str[i] = c;
}
return i;
}