Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-18-2004, 08:08 PM   #1
Registered: Jan 2004
Posts: 482

Rep: Reputation: 30
Unhappy prolem coding switch in c

this is the code for switch:
include <stdio.h>
int i=2;

case 1;
printf("i am in case 1\n");
case 2;
printf("i am in case 2\n");
case 3;
printf("i am in case 3\n");
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
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:
Old 07-19-2004, 03:01 AM   #3
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
Registered: May 2002
Posts: 964

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 AM.

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