关于scanf 的一个小问题 懂得进

来源:百度知道 编辑:UC知道 时间:2024/05/28 02:18:49
#include<stdio.h>
main()
{int s;
double c;
scanf("%d",&s);
scanf("%lf",&c);
printf("%d %f",s,c);
}
同理
#include<stdio.h>
main()
{char s[80], c;
scanf("%s",&s);
scanf("%c",&c);
printf("%s %c",s,c);
}
这样就无法输入字符c
而一定要改成
#include<stdio.h>
main()
{char s[80], c;
scanf("%s %c",&s,&c);
printf("%s %c",s,c);
}
才 行 不知道为什么会出现这种情况

#include<stdio.h>
main()
{char s[80], c;
scanf("%s",&s);
scanf("%c",&c);
printf("%s %c",s,c);
}

#include<stdio.h>
main()
{char s[80], c;
scanf("%s %c",&s,&c);
printf("%s %c",s,c);
}
是不一样的,主要在于电脑没办法识别,因为在第一的程序中两句scanf("%s",&s);scanf("%c",&c);你是这样写的所以电脑就没办法识别,也就不能完全输出。。只要改成这样电脑就能识别了,scanf("%s ",&s);scanf("%c",&c);请注意%s后又个空格,就可以完全输出了。。

而你第二个程序中的一句scanf("%s %c",&s,&c);在你所要输入的两个中,有了空格电脑就能识别!所以就能运行出来!

不要看高了电脑,其实它们的大脑根本就没我们好使!!
如果对这个问题还有什么不明白就HI我!

#include<stdio.h>
main()
{char s[80], c;
scanf("%s\n",&s); //scanf("%s",&s); 改为scanf("%s\n",&s);就行了
scanf("%c",&c);
printf("%s %c",s,c);
}

你出现的错误原因是:一个字符串要有个结束符,当没有结束符时它不能判断什么时候输入结束

首先请楼主注意一下
数组名本身就代表的是首地址