C中的连续用户输入

时间:2016-02-29 01:04:39

标签: c input whitespace scanf fgets

在我的程序中,我有一个看起来像这样的函数

char a[100];
char b[100];
char d[100];

int c;

scanf("%[^\n]%*c", a);
scanf("%[^\n]%*c", b);
scanf("%d", &c);
scanf("%[^\n]%*c", d);

当我运行该函数并给它输入时,输出是

   whatever the first input was
   whatever the second input was
   12345
   ��� //it skips this line and doesn't let me enter anything here

运行该功能两次而不是一次

   whatever the first input was  
   whatever the second input was
   12345
   ��� //skipped


   whatever the first input was //skipped
   whatever the second input was //skipped
   9876 //not skipped
   ��� //skipped 

0 个答案:

没有答案