hi,
this is the code for switch:

include <stdio.h>
main()
{
  int i=2;

  switch(i)
  {
      case 1;
        printf("i am in case 1\n");
        break;
      case 2;
        printf("i am in case 2\n");
        break;
      case 3;
         printf("i am in case 3\n");
         break;
      default;
         printf("i am in default\n");

   }

}

and this is the errors with:
[root@localhost lbin]# gcc -o l105 l105.c
l105.c: In function `main':
l105.c:8: error: parse error before ';' token
l105.c:11: error: parse error before ';' token
l105.c:14: error: parse error before ';' token
l105.c:17: error: parse error before ';' token
l105.c:9: warning: unreachable code at beginning of switch statement

plz help me.
:sad:

Recommended Answers

All 4 Replies

[b]#[/b]include <stdio.h>
int main()
{
   int i=2;
   switch ( i )
   {
   case 1[b]:[/b]
	  printf("i am in case 1\n");
	  break;
   case 2[b]:[/b]
	  printf("i am in case 2\n");
	  break;
   case 3[b]:[/b]
	  printf("i am in case 3\n");
	  break;
   default[b]:[/b]
	  printf("i am in default\n");
   }
   return 0;
}

really i dont see that thhis importance for posting tutorial in Switch
this is poor .. but np study hard ;)

You put:

switch(i)
{
case 1;
printf("i am in case 1\n");
break;
case 2;
printf("i am in case 2\n");
break;
case 3;
printf("i am in case 3\n");
break;
default;
printf("i am in default\n");

}

and the case must finish with ' : ' .

switch(i)
{
case 1:
printf("i am in case 1\n");
break;
case 2:
printf("i am in case 2\n");
break;
case 3:
printf("i am in case 3\n");
break;
default:
printf("i am in default\n");

}

Cya.

commented: Gee. Thanks for the update. You rewrote #2. Good job. -2

You put (Nov 28th 2009):

You put:
<code snipped>
Cya.

He put ( Jul 16th, 2004 ):

hi,
this is the code for switch:
include <stdio.h>
<snipped>

See the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.