I need some suggestions on how to betterer write the following code. I tried the array of arguments, and san through for a match then strcmp but i get massive errors. The code below is the only way i could get it to work.. if some one has any sugestions on hjow to make this better please let me know... The definiton of the class was left out intentionally. if you need this please let me know
Code:
int EXIT=1;
int main()
{
System system = {{getline}, {println}};
while (EXIT)
{
printf("# ");
char exit[] = "exit";
char help[] = "help";
char dataInput[80];
int choice;
gets(dataInput);
if(strcmp (dataInput, exit ) == 0)
{
choice = 1;
}
else if(strcmp (dataInput, help ) == 0)
{
choice=2;
}
else
{
choice=0;
}
switch (choice)
{
case 1: system.out.println("System Shutdown...");
EXIT=0;
break;
case 2: system.out.println("No Help for NOOBS!");
break;
default: printf("Command not recognized!\n");
break;
}
}
return 0;
}
Comment