Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言scanf()函数:执行格式化输入

C语言scanf()函数:执行格式化输入

点击打开在线编译器,边学边练

函数名: scanf

头文件:<stdio.h>

函数原型: int scanf(char *format[,argument,...]);

功 能: 执行格式化输入

参数:char *format[,argument,...]  要输入的格式

返回值:输入的字符个数


程序例:  用于格式化输入

#include<stdio.h>

#include<string.h>

int main(void){

   int a;

   char b;

   printf("请输入数字:\n");

   scanf("%d",&a);

   getchar();

   printf("请输入字符:\n");

   scanf("%c",&b);

   printf("a=%d  b=%c\n",a,b);

   return 0;

}


运行结果

请输入数字:
12
请输入字符:
c
a=12  b=c



本文固定URL:https://www.dotcpp.com/course/536

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)