鸟语天空
C语言—命令行参数
post by:追风剑情 2019-11-20 19:53

示例

//Visual Studio中加上这句才可以使用scanf()
//否则只能使用scanf_s()
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//atof()、atol()
#include <stdlib.h>

//argc: 参数个数 argv[]: 参数数组
//int main(int argc, char **argv)
int main(int argc, char *argv[])
{
	int count = 1;
	printf("Application Name: %s\n", argv[0]);
	printf("The command line has %d arguments:\n", argc - 1);
	for (count = 1; count < argc; count++)
		printf("%d: %s\n", count, argv[count]);

	system("pause");
	return 0;
}

运行测试(从cmd中运行程序)

1111.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容