 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lumina Guest
|
Posted: Tue Mar 06, 2007 2:43 am Post subject: Switch syntax error- |
|
|
I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Chinese Developer Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
We Chinese students of C Language use TurboC,I am willing to give you
suggestion in compiling the source code:
1) switch segment should be included in the main(){}function.
2) there maybe some encumbrance in your code because in C Language ,a
char-type viriable actually stands for a integer value of ASCII.
I cannot express well,but I am really wish this can help u!
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Hans-Bernhard Bröker Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
` wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
|
What you really need is to re-start reading your textbook on C from page
1. The syntax error you got has nothing to do with that switch statment
in particular.
Start by finding the answer to the following question: How would program
execution reach a statement that's outside any function, in a C program?
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Clark Cox Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On 2007-03-05 12:43:23 -0800, "Lumina" <tinalsmith66 (AT) hotmail (DOT) com> said:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
|
If these variables are to be used as counters (as your switch
statement, and their names seems to suggest), then why aren't they
initialized to zero?
| Quote: | char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
|
Well, seeing as the following statements are not inside of a function,
how do you expect them to ever be executed?
| Quote: |
//Statements *
switch ( count)
|
I don't see count defined anywhere.
| Quote: | {
case 'E': count E++;
|
I hope that the space between "count" and "E" was added by your usenet
client. If not, it doesn't make any sense. Also, as written, nothing
will get done for any of the lowercase letters as their 'case'
statement comes *after* the code that you seem to want executed.
| Quote: | case 'e':
break;
case 'A': count A++;
|
....same for the space here
| Quote: | case 'a':
break;
case 'I': count I++;
|
....and here
| Quote: | case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
--
Clark S. Cox III
clarkcox3 (AT) gmail (DOT) com
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
"Lumina" <tinalsmith66 (AT) hotmail (DOT) com> writes:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
|
I have no idea what "C2059" means; it's probably an error code
specific to your compiler. It would have been much more useful to
show the exact error message your compiler produces, and to indicate
which line it refers to.
| Quote: |
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
You should avoid "//" comments in code posted to Usenet. They're not
supported by the C90 standard, but more importantly, line wrapping
with "//" comments is more likely to introduce syntax errors than with
"/* ... */" comments.
Your worst problem is that you can't have a switch statement, or *any*
statement, outside a function. Your program terminates when it
reaches the end of the main() function; when did you expect your
switch statement to be executed?
You also declare variables "countE", but try to refer to "count E".
You can't add spaces in the middle of an identifier.
Your program logic is badly messed up as well (enough so that it's
difficult to figure out what you meant to do), but fix the syntax
errors first.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Douglas A. Gwyn Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
Lumina wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
|
I don't know what "C2059" is supposed to be, but assuming a C program:
| Quote: | int main(void)
{
...
}// main
switch ( count)
{
...
}//switch
|
You cannot have a switch statement at file scope. Put it inside
the definition of main where it belongs.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Michael Tiomkin Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On Mar 5, 10:43 pm, "Lumina" <tinalsmit...@hotmail.com> wrote:
| Quote: | I need some assistance on getting past C2059 sytax
|
You don't mention what compiler you use. Every compiler has its own
error codes.
| Quote: | error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
|
Please move the next statement after the end of your switch
statement. In some languages, e.g. Assembler, you are allowed
to insert code outside of the functions. Unfortunately,
in C/C++ you can only put data declarations/definitions
outside of the functions.
| Quote: | }// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
--
-- |
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Barry Schwarz Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On 05 Mar 2007 20:43:23 GMT, "Lumina" <tinalsmith66 (AT) hotmail (DOT) com>
wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
|
Your main function ends here.
| Quote: |
//Statements *
switch ( count)
|
These statements are not allowed at file scope. They need to be in a
function. It appears as if your closing brace above should be moved
after these statements, therby making these statements part of main.
| Quote: | {
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
Remove del for email
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jack Klein Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On 05 Mar 2007 20:43:23 GMT, "Lumina" <tinalsmith66 (AT) hotmail (DOT) com> wrote
in comp.lang.c.moderated:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
|
First you need some assistance in learning how to post to usenet
asking for help.
There is more than one C compiler, you know, and things like "C2059"
are NOT defined by the C language. You have not told us what "C2059"
means, or even what compiler you received it from.
When you post code that is giving you an error, you need to copy and
paste the complete text of the error message, and also indicate some
way, perhaps by adding a comment, which line of your source code the
compiler pointed to as containing the error.
The next problem is that what you have posted is NOT the code that you
compiled. If you don't know the cause of the error, how do you know
it is not in the source that you replaced with "//Statements *"? How
do we know that whatever is really there is not the cause of the error
message.
I just happened to take a guess that your compiler is some version of
Microsoft's Visual C++, and searched for the string "C2059" on
http://msdn.microsoft.com. This resulted in 26 hits, and without even
going to the linked pages, I can see that most of them say this:
"syntax error : ' token ' The token caused a syntax error."
Also, the next sentence in the description is "To determine the cause,
examine not only the line listed in the error message, but also the
lines above it."
Now IF what you posted is close to what you tried to compile, and IF
there isn't an error in the code you replaced with "//Statements *",
then see below for a suggestion about what your problem might be.
| Quote: | #include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
|
It appears that you have ended your main() function just above here.
This function really does nothing at all, just defines some auto
variables, some initialized, some not, and then the program ends
without using them.
| Quote: | //Statements *
switch ( count)
|
If the compiler mentions this line above as causing the error, and if
you haven't omitted crucial code, you appear to be writing a switch
statement at file scope, outside the body of any function. You can't
do this in C, all switch statements, and all other executable code,
must be inside functions.
| Quote: | {
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
If my suggestion is not correct, because you have snipped so much of
the real code from your example, then you need to cut your real code
down to the smallest sample that generates the error message, add a
comment to the line the compiler mentions in the error message, and
copy and past the code, and copy and past the exact text of the error
message, into another post.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jonathan Leffler Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
Lumina wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
|
declarations!
| Quote: | char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
|
This close brace finishes main() - you need to include the switch inside
a function - one with the variables declared, too.
| Quote: | //Statements *
switch ( count)
{
case 'E': count E++;
|
Don't include spaces in the middle of variable names?
| Quote: | case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler (AT) earthlink (DOT) net, jleffler (AT) us (DOT) ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Kenneth Brody Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
Lumina wrote:
| Quote: |
I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
|
First, the switch statement is outside of any function. (You have
closed the brace for main(), as noted in your comment.
Second, you can't have a space in "count E++" for example. You need
to have "countE++" to increment countE.
Third, while not a syntax error, but possibly a logic error, the
increments won't happen for lower-case letters. You need to have
the increment after the case:
case 'E':
case 'e':
countE++;
break;
Finally, you probably want to initialize your counts to zero.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap (AT) gmail (DOT) com>
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Arun Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On Mar 5, 3:43 pm, "Lumina" <tinalsmit...@hotmail.com> wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
=> why space between cound and E++? should n't it be countE++?
case 'e':
break;
case 'A': count A++;
=> why space between cound and A++? should n't it be countA++?
case 'a':
break;
case 'I': count I++;
=> why space between cound and I++? should n't it be countI++? |
| Quote: | case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
|
Could you post the error? and full program file as is?
Also dont you want to count small letter e a i? if you do want to
count then keep the statement countI++ below case 'i': statement.
-Arun Joseph
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
R Pradeep Chandran Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On 05 Mar 2007 20:43:23 GMT, "Lumina" <tinalsmith66 (AT) hotmail (DOT) com>
wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
|
<snipped something that tries to look like a C program>
If you want someone to help you, you need to post a short, complete C
program and you need to explain the error you are getting. You can
copy and paste the actual compiler output. Before you do that, it
might be a good idea to check what the compiler documentation says
about the error.
The ISO standard does not define any C2059 syntax error.
<OT>
The error seems to be one generated by MSVC. MSDN has a reasonably
good explanation of the reasons why this error occurs.
</OT>
Have a nice day,
Pradeep
--
All opinions are mine and do not represent the views or
policies of my employer.
R Pradeep Chandran rpc AT pobox DOT com
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
On Mar 5, 4:43 pm, "Lumina" <tinalsmit...@hotmail.com> wrote:
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
|
This is interesting. Your counts are being init to ASCII value of
letters. Is this what you want?
| Quote: | char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
|
Your var name is "countE" not "count E" (at least it is in your main()
function and tokens in C/C++ cannot have whitespaces in them. I'm
assuming that you are declaring these somewhere). And I could be
wrong, but do you really want only 'E' to increment countE and 'e' to
do nothing?
Adrian
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
ForestDB Guest
|
Posted: Sat Mar 10, 2007 6:48 pm Post subject: Re: Switch syntax error- |
|
|
| Quote: | case 'E': count E++;
case 'e':
break;
|
Is there a space between count and E++?
--
ForestDB
"Lumina" <tinalsmith66 (AT) hotmail (DOT) com> wrote in message
news:clcm-20070305-0011 (AT) plethora (DOT) net...
| Quote: | I need some assistance on getting past C2059 sytax error-please help
#include <stdio.h
#include <ctype.h
int main(void)
{
int count;
//local delcarations
char countE = 'E';
char countA = 'A';
char countI = 'I';
char ch ;
return 0;
}// main
//Statements *
switch ( count)
{
case 'E': count E++;
case 'e':
break;
case 'A': count A++;
case 'a':
break;
case 'I': count I++;
case 'i':
break;
default: printf ("print Error--Not A, E, or I\a\n");
break;
}//switch
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.
-- |
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|