Haven't programmed in C in a while, so I'm surely missing something here but I can't figure out what it is.
I have two strings, as shown below:
char toMatch[] = "--exit--"; char entry[1024]; Through this program, I have a while loop that accepts user input to modify the string entry throughout the program. I would like to exit this while loop when entry equals toMatch.
I thought this was easy to do with the strcmp function, but it's not working for some reason. Originally I had this:
while(strcmp(entry, toMatch) != 0) { // accept user input here to modify entry } However, this didn't work. So I added one line of code to clear the contents of entry before accepting user input again:
while(strcmp(entry, toMatch) != 0) { memset(entry, 0, sizeof(entry)); // accept user input here to modify entry } This doesn't work either. I need to have entry be this long, because the entry of the user can be any length smaller than this. I have no idea why strcmp() is not working, so I think I'm missing something that should be obvious.