关于main(int argc,char *argv[])的应用问题,求大虾解一下代码那错了,想输入命令行比如changeday 1输出monday。
#include <stdio.h>#include <stdlib.h>
#include <string.h>
char *Day[]={"Monday","Tuesday","Wednesday","thursday","Friday","Saturday","Sunday"};
void Dchange(char *pstr);
void main(int argc, char *argv[])
{
if(argc!=2) //判断输入格式是否为两位
{
printf("输入格式错误 ,请按照例子输入,如ChangeDay 1");
exit(0);
}
if(*(argv+1)>='1'&&*(argv+1)<='7')
{
printf("英文表示为:\n");
Dchange(argv[1]);
}
else
{
printf("输入为整数且范围在1~7");
exit(0);
}
}
void Dchange(char *pstr)
{
printf("%s",Day[(atoi(pstr)-1)]);
}