Escaping an infinite loop
I am trying to work on a note program that I have been working on for a long time and wanted to add a new feature. Up until now the user has only been able to enter a 1 line note. I wanted to make it so that they can use as many lines as they want. This is how I have it so far. Code:
while(1){
fgets(text,1000,stdin);
fprintf(fp,text);
}
That works but then the user needs to entirely exit the program to stop it. I wanted to add an if statement so that they could enter a character to terminate the note. Like this... Code:
while(1){
fgets(text,1000,stdin);
if(text=='~'){
break;
}
fprintf(fp,text);
}
This compiles with no warnings but then when I run it just keeps going and does not exit the infinite loop when they enter a ~. Why is this?
~Sven