版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
功能:
格式化标准输入,写入到内存单元中。
Reads data from stdin and stores them according to the parameter format into the locations pointed by the additional arguments.
/*scanf example */
#include <stdio.h>
int main()
{
char str[80] = {0};
int i = 0;
printf("Enter your family name:\n");
scanf("%79s", str);
printf("Enter your age:\n");
scanf("%d", &i);
printf("Mr %s, %d years old \n", str, i);
return 0;
}
输出
[root@localhost test]# ./demo
Enter your family name:
ming
Enter your age:
11
Mr ming, 11 years old
[root@localhost test]#