Using fgets() right after getchar()
问题 void read_stdin(trace_t* trace, state_t state, action_t** action_list) { // initial stage int c; while ((c = getchar())!= EOF && c!='#') { if (my_isalpha(c)==LOWERCASE) { state[c-ASCII_CODE_LOWER_A] = '1'; } } printf("%s\n", state); char str[2]; fgets(str, 2, stdin); printf("%s", str); } If '#' is the last character I enter in the getchar() loop, fgets() records the newline character from when I press enter and skips to the print statement immediately (which prints the '\n') I could fix this