LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2004, 08:08 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 537

Rep: Reputation: 30
Unhappy prolem coding switch in c


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.
 
Old 07-18-2004, 08:11 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You need colons ':' instead of semicolons ';' at the end of each case statement (and default).

case 1:
case 2:
...
default:
 
Old 07-19-2004, 03:01 AM   #3
south_river
LQ Newbie
 
Registered: Jul 2004
Location: China
Distribution: Fedora Core 1
Posts: 4

Rep: Reputation: 0
Quote colons ':' instead of ';'

it is right
 
Old 07-19-2004, 10:52 AM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
It's homework, I think. The same post is on several other Linux Programming forums.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
graphics update prolem bograt Linux - Hardware 1 02-22-2005 12:00 PM
CD Burning prolem Sherlok Slackware 17 10-18-2004 09:23 PM
not very nice kernel prolem plm Slackware 21 09-16-2003 01:08 PM
Prolem in installing from source... Baran Linux - Newbie 2 09-09-2003 03:58 AM
Snort Prolem. Di0de Linux - Software 4 07-24-2003 06:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration