I am trying to read user input with multiple fields. But the number of fields is not specified. I want to read all the words until the carriage returns. I tried this code but it does not work:
char str[256]; while(1) { scanf("%s", str); if(str[strlen(str)] == '\n') break; else printf("Got %s\n", str); }
User input examples:
1. save file1
I need to parse the repository and file1 and exit the loop.
2. Save file1 file2
I need to parse store, file1 and file2 and exit the loop.
It's amazing how to get out of the loop when the carriage returns.
thanks.
source share