scanf()函数和gets()函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wo_aisilebiancheng/article/details/50783354
 
 
/*
scanf()函数在输入字符串时以空格、制表符、或回车表示字符串
的结束,因此scanf()无法输入带有空格、制表符、回车的字符串。
用gets()方法就可以解决这个问题。
*/
#include <stdio.h>
int main() {
	char ch[40];
	printf("请输入字符串:computer & C\n");
	gets(ch);
	puts(ch);// 输出字符串并且自动换行。output:computer & C
	printf("请输入字符串:computer & C\n");
	scanf("%s", ch);
	printf("%s\n", ch);// output:computer
	return 0;
}


猜你喜欢

转载自blog.csdn.net/wo_aisilebiancheng/article/details/50783354
今日推荐