get()的用法

gets


【1】函数:gets
【2】头文件:stdio.h
【3】功能:从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在str指针所指向的字符数组中。换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字符串。
【4】注意:本函数可以无限读取,不会判断上限,所以程序员应该确保str的空间足够大,以便在执行读操作时不发生溢出。
【5】示例:
#include"stdio.h"
void main()
{
char str1[5];
gets(str1);
printf("%s\n",str1);
}

#include<stdio.h>
#include<string.h>
void main()
{
char a[100];
printf("请输入一个单词\n");
puts(gets(a));
}


猜你喜欢

转载自blog.csdn.net/qiumingsheng/article/details/6587980
今日推荐