Printf statments not printing in order

后端 未结 2 690
甜味超标
甜味超标 2020-12-12 07:27
typedef struct node_s{
int data;         
struct node_s *next;
}node_t;                

void insert(node_t *pointer, int data){
     while(pointer->next != NULL)         


        
2条回答
  •  我在风中等你
    2020-12-12 08:29

    Remove \n from the very first scanf

    scanf("%d\n", &input);
    

    What is that \n doing there? That is what is causing your scanf to "linger", waiting for extra input, instead of terminating immediately.

    That \n has special meaning for scanf. When you use a whitespace character (space, tab or \n) in scanf format specifier, you are explicitly asking scanf to skip all whitespace. If such character is used at the very end of scanf format string, then after reading the actual data scanf will continue to wait for input until it encounters a non-whitespace character. This is exactly what happens in your case.

提交回复
热议问题