Hier ist ein Programm, das einige Informationen über meine selbst in diesem Programm drucken, wenn der Benutzer scannt/n seinen Namen und usw. drucken, aber wenn ich dieses Programm mit gcc laufen lasse, druckt nichts überhaupt. Ich muss die Parameter mit Argv und Argc scannen. wie kann ich das lösen?Drucken mit Argv und 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);
}
Was ist die erste Überraschung, die Sie mit diesem Programm erfüllen? – fluter
Vergleichen Sie Strings mit strcmp aus string.h. Und Argc sollte Ihre FOR-Schleife begrenzen, nicht die GRÖSSE. – jboockmann
was genau ist 'case'/n ': '? –