Hi all,
Second newbie question of the day! I'm building a program that gets input from the user. I am using scanf to get a line and then do some processing and this is working fine. The problem comes when I try to loop through this until the user enters 'quit'. It works fine the first time round but then just goes into an infinite loop. The code is below:
Code:
while (1) {
char expr[100] = {0};
printf("Input Expression:");
scanf("%[^\n]", expr);
if (strcmp(expr, "quit") == 0) { return 0; }
// do stuff here
printf("\n");
}
This has been simplified by removing some extra code that processes the input however I don't think this is where the problem lies. I think it's something to do with the scanf but am unsure what. Any pointers greatly appreciated!
Cheers,
James