C语言教程:gets()和puts()函数

2018-10-0708:07:12编程语言入门到精通Comments5,140 views1字数 322阅读模式

gets()函数从用户读取字符串,puts()函数打印字符串。这两个函数都在<stdio.h>头文件中定义。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6439.html

下面来看看一个简单使用gets()puts()函数来读写字符串的程序。创建一个源文件:gets_and_puts.c,其代码如下所示 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6439.html

#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  

}
C

执行上面示例代码,得到以下结果 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6439.html

Enter your name: maxsu
Your name is: maxsu
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6439.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/6439.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定