954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error coding switch

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:

abd2
Newbie Poster
3 posts since Jul 2004
Reputation Points: 13
Solved Threads: 0
 
<strong>#</strong>include <stdio.h>
int main()
{
   int i=2;
   switch ( i )
   {
   case 1<strong>:</strong>
	  printf("i am in case 1\n");
	  break;
   case 2<strong>:</strong>
	  printf("i am in case 2\n");
	  break;
   case 3<strong>:</strong>
	  printf("i am in case 3\n");
	  break;
   default<strong>:</strong>
	  printf("i am in default\n");
   }
   return 0;
}
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

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

mGabriel
Newbie Poster
1 post since Nov 2009
Reputation Points: 8
Solved Threads: 0
 

You put (Nov 28th 2009):

You put: Cya.


He put ( Jul 16th, 2004 ):hi,
this is the code for switch:
include

See the problem?

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You