当只有两个 scanf 调用时,为什么这要求三个输入?
Why does this ask for three inputs when there are only two scanf calls?
下面的代码有两个 scanf
调用,但是当我 运行 它时,它要求三个输入。我假设问题来自 \n
,但为什么呢?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s,*t;
s=malloc(1024);t=malloc(1024);
scanf("%s\n",s);
scanf("%s\n",s);
if(s==t)
{
printf("Same!\n");
}
else
{
printf("Different\n");
}
}
下面的代码有两个 scanf
调用,但是当我 运行 它时,它要求三个输入。我假设问题来自 \n
,但为什么呢?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s,*t;
s=malloc(1024);t=malloc(1024);
scanf("%s\n",s);
scanf("%s\n",s);
if(s==t)
{
printf("Same!\n");
}
else
{
printf("Different\n");
}
}