For Programmers: Free Programming Magazines  


Home > Archive > Learn C and C Sharp > February 2005 > what is the problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author what is the problem
nick

2005-02-18, 4:00 am

the error messages:

c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : ';'
c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : 'type'
c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2061: syntax error :
identifier 'isSymbol'


#include <stdio.h>
char tmpdigit[1024];
int step;
bool isSymbol(char);

void main(){
char ch;

while((ch=getchar())!=EOF){
bool c;
c=isSymbol('+');
if (ch=='\n'){


}else if(ch==' '){
continue;
}


}



}
bool isSymbol(char ch){
bool flag;
flag=false;
switch (ch){
case '+':
case '-':
printf("elseif");
break;
case '*':
case '/':
case '(':
case ')':
break;
}
return flag;
}



Artie Gold

2005-02-18, 4:00 am

nick wrote:
> the error messages:
>
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : ';'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : 'type'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2061: syntax error :
> identifier 'isSymbol'
>
>
> #include <stdio.h>
> char tmpdigit[1024];
> int step;
> bool isSymbol(char);


See: http://www.comeaucomputing.com/techtalk/c99/#bool
>
> void main(){

int main(void)
> char ch;
>
> while((ch=getchar())!=EOF){
> bool c;
> c=isSymbol('+');
> if (ch=='\n'){
> }else if(ch==' '){
> continue;
> }
> }
> }


> bool isSymbol(char ch){
> bool flag;
> flag=false;
> switch (ch){
> case '+':
> case '-':
> printf("elseif");
> break;
> case '*':
> case '/':
> case '(':
> case ')':
> break;
> }
> return flag;

Why bother with `flag' if you only return `false'? But see above...
> }
>
>
>

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
nick

2005-02-18, 4:00 am

when i type
#include <stdbool.h> in VC

then compile ,the error occur

c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\Assignment2\ex2_2 v5\2_2.c(2): fatal error C1083: Cannot open
include file: 'stdbool.h': No such file or directory


Andrey Tarasevich

2005-02-18, 4:00 am

nick wrote:
> the error messages:
>
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : ';'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error : 'type'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2061: syntax error :
> identifier 'isSymbol'
> ...


Your are compiling your code as C (not C++) code. Type 'bool' is not
present in the original C language. It was introduced relatively
recently in new C standard - C99. However, your compiler does not
support C99.

Either forget about 'bool' or use C++.

--
Best regards,
Andrey Tarasevich

Bart van Ingen Schenau

2005-02-18, 4:00 pm

nick wrote:

> when i type
> #include <stdbool.h> in VC
>
> then compile ,the error occur
>
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(2): fatal error C1083: Cannot open
> include file: 'stdbool.h': No such file or directory


That means that your compiler does not support the bool type when
compiling C code.
For such compilers, you can use the type int for your boolean values,
using the value 0 for false and a non-zero value for true (typically,
the value 1 is used)

Alternatively, you can create your own stdbool.h header, using these
contents:

#ifndef __H_STDBOOL__
#define __H_STDBOOL__

#ifndef bool
#define bool int
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif

#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
#endif

#endif /* __H_STDBOOL__

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
Old Wolf

2005-02-19, 3:58 am

nick wrote:
> the error messages:
>
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error :

';'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2059: syntax error :

'type'
> c:\Documents and Settings\Administrator\My Documents\Visual Studio
> Projects\Assignment2\ex2_2 v5\2_2.c(5): error C2061: syntax error :
> identifier 'isSymbol'
>
> #include <stdio.h>
> char tmpdigit[1024];
> int step;
> bool isSymbol(char);


ANSI C does not have 'bool' (and from your other posts,
it looks like your compiler doesn't support ISO C99).
An easy solution would be:
typedef int bool;
enum { FALSE, TRUE };
>
> void main(){


int main(void) {

> char ch;
>
> while((ch=getchar())!=EOF){


'ch' should be an int, otherwise it may never match EOF.
Read the FAQ.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com