/***********************************************************
A test main programme with parameter
ruanbanmao 2011-12-16
************************************************************/
# include
void info()
{
printf("Information:\n");
printf("Main function with parameter\n");
printf("Auther: ruanbanmao\n");
printf("date: 2011-12-16\n");
}
void help()
{
printf("Options:\n");
printf("-h: Help information\n");
printf("-i: The information for the programme\n");
printf("-w: Say hello world\n");
}
int main(int argc, char *argv[])
{
if (argc > 2)
printf("Too many parameter!\n");
else if(argc < 2)
{
printf("Pls input an option\n");
help();
}
else
{
if (*argv[1] != '-')
{
printf("Error parameter\n");
help();
}
else
{
switch(*(argv[1]+1))
{
case 'h':
help();
break;
case 'i':
info();
break;
case 'w':
printf("w: say hello world\n");
break;
default:
printf("Fault options\n");
help();
break;
}
}
}
return 0;
}