首页 > 编程语言 > 详细

C语言输入输出

时间:2020-04-05 02:25:34      阅读:72      评论:0      收藏:0      [点我收藏+]

 printf()和scanf()

scanf(const char *format, ...) 函数从标准输入流 stdin 读取输入,并根据提供的 format 来浏览输入。

printf(const char *format, ...) 函数把输出写入到标准输出流 stdout ,并根据提供的格式产生输出。

#include <stdio.h> 
int main()
{
    printf("hello\n"); 
    printf("world!!!\n");
    int testInteger = 5;
    printf("Number = %d\n", testInteger);
    char c[]="Who am i!";
    printf("%s\n",c);
   float f,j;
    printf("Enter a number: ");
    scanf("%f   %f",&f,&j);
    printf("Value = %.2f   %f", f,j);
    return 0;
}
hello
world!!!
Number = 5
Who am i!
Enter a number: 9977    886
Value = 9977.00   886.000000

gets() & puts()

gets()函数从 stdin 读取一行到 s 所指向的缓冲区,直到一个终止符或 EOF。

puts()函数把字符串 s 和一个尾随的换行符写入到 stdout

#include <stdio.h>
int main(){
   char s[200];
   printf("please input a word:");
   gets(s);
   printf("your input is:");
   puts(s);
   return 0;
}
please input a word:welcome to  China!!!
your input is:welcome to        China!!!

 

C语言输入输出

原文:https://www.cnblogs.com/pfeiliu/p/12635100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!