C语言gets()和puts()函数

gets()函数从用户读取字符串,puts()函数打印字符串。这两个函数都在<stdio.h>头文件中定义。

下面来看看一个简单使用gets()puts()函数来读写字符串的程序。创建一个源文件:gets_and_puts.c,其代码如下所示 -

#include<stdio.h>  

void main() {
    char name[50];
    printf("Enter your name: ");
    gets(name); //reads string from user  
    printf("Your name is: ");
    puts(name);  //displays string  

}

执行上面示例代码,得到以下结果 -

Enter your name: maxsu
Your name is: maxsu

上一篇: C语言字符串 下一篇: C语言字符串函数