C
candy
why this code enters an infinite loop.
i dont know what is the problem in
while((c=fgetc(file))!='\n' && c!='\r')
It enters the infinte loop in this statement.
The aim of the program is to remove comments of type //
It uses a temp file and after the operation , deletes the file.
//this is a test.
#include<stdio.h>
#define FALSE 0
#define TRUE 1
//this is a test.
int main(void){
char c;
FILE *file,*temp;
int last=FALSE;
file= fopen("file2.c","r");
temp=fopen("TEMP","w+");
if(!file || !temp){
printf("error");
exit(1);
}
while((c=fgetc(file))!=EOF){
if(c=='/')
if(last==TRUE){
while((c=fgetc(file))!='\n' && c!='\r')
;
}
else
last=TRUE;
else{
last=FALSE;
fprintf(temp,"%c",c);
}
}
return 0;
}
i dont know what is the problem in
while((c=fgetc(file))!='\n' && c!='\r')
It enters the infinte loop in this statement.
The aim of the program is to remove comments of type //
It uses a temp file and after the operation , deletes the file.
//this is a test.
#include<stdio.h>
#define FALSE 0
#define TRUE 1
//this is a test.
int main(void){
char c;
FILE *file,*temp;
int last=FALSE;
file= fopen("file2.c","r");
temp=fopen("TEMP","w+");
if(!file || !temp){
printf("error");
exit(1);
}
while((c=fgetc(file))!=EOF){
if(c=='/')
if(last==TRUE){
while((c=fgetc(file))!='\n' && c!='\r')
;
}
else
last=TRUE;
else{
last=FALSE;
fprintf(temp,"%c",c);
}
}
return 0;
}