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:

Edited 7 Years Ago by Nick Evan: Added code-tags

[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.

Comments
Gee. Thanks for the update. You rewrote #2. Good job.

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?

This article has been dead for over six months. Start a new discussion instead.