scanf的用法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/ming2453755227/article/details/102606319

功能:
格式化标准输入,写入到内存单元中。
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]# 

猜你喜欢

转载自blog.csdn.net/ming2453755227/article/details/102606319