-
switch statement
what is wrong with the following snippet? are intergers not allowed in switch statements?
Code:
#include <stdio.h>
int
main()
{
int i;
while (1) {
printf("1 prints 1\n2 prints 2\n3 prints 3\n\n");
scanf("%i", i);
switch (i) {
case 1: printf("one");
break;
case 2: printf("two");
break;
case 3: printf("three");
break;
default: printf("error");
break;
}
}
return 0;
}
I get a segmentation fault when I run it.
-
You are running in a never-ending loop. Remove that while() loop.
-
sorry, I posted this the lazy way. the loop is needed in the program this is for (this is just the part that's not working. In the actual program, each case statement has a function.
-
-