Why does scanf ask twice for input when there's a newline at the end of the format string?

后端 未结 6 943
野的像风
野的像风 2020-11-22 04:52
#include 
#include 
#include 

char *method1(void)
{
    static char a[4];
    scanf(\"%s\\n\", a);
    return a;
}

i         


        
6条回答
  •  鱼传尺愫
    2020-11-22 05:05

    you can use either of these to avoid the mentioned problem : scanf("%s",a); or scanf("\n%s",a);

提交回复
热议问题