There are a couple of things you can do to debug this. First - read in the entire input line, rather than the first word. The safe way to do this is with getline() - it will notice if the line is too long for your input buffer, and adjust things (updated with thanks to Elchonon Edelson)
char *myString;
int stringLength;
size_t bufLength=0;
myString = NULL; // let getline() adjust the string
stringLength = getline(&myString, &bufLength, stdin)
Next, print out the line as entered:
printf("The line is <<%s>>\n", myString);
Note the use of << and >> to show where the string starts / ends - see white space etc.
Finally, print out the string one character at a time, including the hex code:
for(ii = 0; ii < stringLength; ii++) {
char ch;
ch = myString[ii];
printf("myString[%d]: character '%c', hex code %02x\n", ii, ch, ch);
}
This should help you pinpoint the problem.
|character. Can you copy-and-paste the output for a run of the program? One unlikely possibility: could|be mapped to something in your tty settings? Runsttyto see your settings. But as @CharlieBurns says, you will get a bit of a mess if there are spaces in your input. Try typing"1 2 3 4"as input; is that the same kind of mess you get with|?