How to use strings in a switch statement? For now I used the first letter of the string in the switch statement. Here is my code. I want to use the whole string in char a, b, c as the input in switch. How to?
int main()
{
char input[10];
int x, y, i;
int AX;
char a[] = "ADD";
char b[] = "PRT AX";
char c[] = "EXIT";
for (i = 0; i < 100; i++)
{
printf("\nType ADD following the two numbers to be added\n");
printf(" PRT AX to display the sum\n");
printf(" EXIT to exit program\n");
printf("---->");
scanf("%s", &input);
switch (input[0])
{
case 'A':
printf("\nEnter two numbers you want to add:\n");
scanf("%d %d", &x, &y);
break;
case 'P':
printf("Sum: %d\n\n", x + y );
break;
case 'E':
exit(0);
default:
i++;
}
}
return 0;
}