![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
Help with syntax error in C
Ok so I'm currently taking a course on C and for one of my assignments I am getting these compile time warnings/errors:
Exercise1.c: In function `main': Exercise1.c:16: warning: passing arg 1 of `atol' from incompatible pointer type Exercise1.c:17: warning: passing arg 1 of `atoi' from incompatible pointer type Exercise1.c:19: warning: passing arg 1 of `sprintf' from incompatible pointer type Exercise1.c:20: warning: passing arg 1 of `strcpy' from incompatible pointer type Exercise1.c:27: warning: passing arg 1 of `atoi' from incompatible pointer type Exercise1.c:34: warning: passing arg 1 of `strcmp' from incompatible pointer type Exercise1.c:35: warning: passing arg 1 of `atoi' from incompatible pointer type Exercise1.c:40: warning: passing arg 1 of `atoi' from incompatible pointer type Exercise1.c:41: error: syntax error before "else" Exercise1.c: At top level: Exercise1.c:53: error: syntax error before '}' token I have been using Java for 3 years now and have just started C. Can anyone help me find these two syntax errors and explain them for me as I cannot seem to find them myself. Thanks, Andrew c Syntax (Toggle Plain Text)
|
|
|
|
|
|
#2 |
|
C/C++ Developer
Join Date: Sep 2008
Location: Florida, USA
Posts: 43
Rep Power: 0
![]() |
Re: Help with syntax error in C
It is in your declarations for the character buffers ... if you want to allocate space for a null-terminated string, you would do it this way:
/* You have this ... */ char *myString[80]; /* ... that allocates a buffer for 80 char* items ... what you want is ... */ char myString[80]; /* this is an 80-char buffer for a string */ Essentially, you have declared a collection of string pointers, not a string itself. HTH
__________________
-- William |
|
|
|
|
|
#3 | |
|
Not a user?
Join Date: Sep 2007
Posts: 308
Rep Power: 2
![]() |
Re: Help with syntax error in C
Quote:
|
|
|
|
|
|
|
#4 | ||
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
Re: Help with syntax error in C
Quote:
The warnings being issued are can be bypassed and the program will ruin after issuing these warnings. The errors I am talking about are for lines 41 & 54 (the error says 53 & 40 but I ended up adding an extra blank line to make the code more legible. Thank you for your response Jabo. Quote:
MasterWill I ended up changing char *string[101] to char myString[101] creating a string buffer however I am still getting these same errors. |
||
|
|
|
|
|
#5 |
|
Banned
![]() ![]() |
Re: Help with syntax error in C
What MaterWill suggested must be applied to every string, not just his particular example.
A C-string is an array of characters. Not an array of character pointers. Do some googling for how to use strings in C.
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
Re: Help with syntax error in C
Thanks Sane, I'll definitely look up how to use strings better in C.
The advice took away all the warnings however I am still getting these compile time errors. Exercise1_palmer.c: In function `main': Exercise1_palmer.c:42: error: syntax error before "else" Exercise1_palmer.c: At top level: Exercise1_palmer.c:54: error: syntax error before '}' token |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 244
Rep Power: 3
![]() |
Re: Help with syntax error in C
the else if on line 42 is not proceeding after an if statement. you need to do something about line 41.
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
Re: Help with syntax error in C
|
|
|
|
|
|
#9 |
|
12 years old
Join Date: Nov 2007
Posts: 105
Rep Power: 0
![]() |
Re: Help with syntax error in C
you're passing char ** when you meant char *. change the char *str[len] to char str[len]
![]() also, mark = atoi(quiz3); if (...) { .... } mark = atoi(quiz13); else if (...) { .... }remove the 'else' statement because it is not what you meant |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1 [STOPED] | jackparsons | PHP | 3 | Aug 21st, 2008 12:59 AM |
| syntax error in Mysql... | ktsirig | PHP | 1 | Feb 3rd, 2007 2:30 PM |
| Header file internal errors | kruptof | Coder's Corner Lounge | 2 | Jan 14th, 2007 2:12 PM |
| Which test syntax to use? | aznluvsmc | Bash / Shell Scripting | 4 | Jan 17th, 2006 7:00 PM |
| From C syntax to C++ syntax | Navid | C++ | 13 | Jan 15th, 2006 8:42 AM |