這裏是一個程序,它在本程序中打印一些關於我自己的信息 如果用戶掃描/ n其打印名稱和 等,但是當我使用gcc運行此程序時,在所有。 我需要使用argv和argc來掃描參數。 我該如何解決?使用argv和argc打印
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
int main(int argc, char** argv)
{
for (int i = 1; i < SIZE; i++)
{
if (argv[i] == ' ')
{
break;
}
if (argv[i] == 'n' || argv[i] == 'b' || argv[i] == 'f' || argv[i] == '?' && argv[i - 1] == '/')
{
switch (i)
{
case 'n':
printf("my name is : Daniel Zingerman \n");
break;
case 'b':
printf("my birth date is: 2/11 \n");
break;
case 'f':
printf("my favorite food is: ice cream \n");
break;
case '?':
printf("the instruction of the program:");
printf("There is a lot of parameters you can scan into the program:");
printf("1. /n - printing the name");
printf("2. /b - printing the birth date");
printf("3. /n - printing the favorite food");
printf("4. /? - printing the instructions");
break;
}
}
}
system("pause");
return(0);
}
什麼是你遇到了這個程序的第一個驚喜? – fluter
使用string.h中的strcmp比較字符串。而ARGC應該限制你的循環,而不是SIZE。 – jboockmann
'case'/ n'究竟是什麼:'? –