|
 |
|
 |
 |
03-24-2005, 11:56 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
Perplexing Error on C Code
et al.
I have been trying to get this code to work for the last couple of hours and I can't seem to understand the error I am receiving, which is:
C:\Dev-Cpp\prog6.cpp In function `void num_read()':
42 C:\Dev-Cpp\prog6.cpp syntax error before `)' token
46 C:\Dev-Cpp\prog6.cpp syntax error before `{' token
C:\Dev-Cpp\Makefile.win [Build Error] [prog6.o] Error 1
If I remove the funtion which contains the getchar() function in the while loop and use just one function, mainly the num_read() func. then the code compiles. Any suggestions would be appreciated.
Here is the code:
Code:
/************************************************************************
*****Name:
*****Date:
*****Problem:
*****Description:
***********************************************************************/
#include <stdio.h>
/****Demostrates Declerations****/
int num_input, i, j, k, l, m, n, o, p, q, r;
void num_read(void);
void num_ratio(void);
void num_scan(void);
/****Main Function****/
main(){
num_read();
num_ratio();
}
/****Function Definitions****/
void num_read(void){
//scanf reads ten number, if less are inputed an error is called
printf("Please enter 10 numbers in sequence!\n");
printf(">>");
num_scan();
while (num_input < 10){
while (getchar() != '\n'){
/*Hello*/
}
printf("You only entered %d numbers, please enter 10 numbers\n", num_input);
printf("Please enter 10 numbers in sequence!\n");
printf(">>");
num_scan();
}
void num_scan(void){
num_input = scanf("%d %d %d %d %d %d %d %d %d %d", &i, &j, &k, &l, &m, &n, &o, &p, &q, &r);
}
void num_ratio(void){
printf("Here are those ratios:\n");
printf("%d %d %d %d %d %d %d %d %d %d", i, j, k, l, m, n, o, p, q, r);
}
/*****************************************/
thanks. et
__________________
Last edited by Valmont : 03-24-2005 at 12:23 PM.
|
|
|
03-24-2005, 02:06 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
look at void num_read(), see if there isn't ,missing a '}' at the end of that..
Another thing, try using int as return type of your functions, eventho they never return anything useful, but having somethign to return than void, is allways considered good programming style.
|
|
|
03-24-2005, 02:29 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
Looked at '}' and added int
I checked out to make sure my }'s were OK, and they were. I also changed the function type to 'int' and still have no affect.
If I compile using a different compiler I get the following error, even after the type change:
prog6_2.c: In function `num_read':
prog6_2.c:54: error: syntax error at end of input
anymore ideas. thanks.
__________________
|
|
|
03-24-2005, 03:17 PM
|
#4 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
I added an extra '}' to the num_read(), and it compiled and ran success fully.. dont know what it could be, if thats not working on your system.. anyway I'm way too drunk right now to go any further into that, the only thing that would make any sence in my mind right now, would be threadding of programs and exchanging values across different threads.. the last time I did that, was with a feever of 40+ degree celcius.
|
|
|
03-24-2005, 03:34 PM
|
#5 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
Added } to the code and it worked... one more question.
I only looked at the set of }'s and I thought it was OK. To continue with the program I also have to make sure that the numbers which are entered are in sequence, in other works 1234 would be OK but 1245 would not. Have any ideas on how to adjust this code to make sure the nubers where in sequence? Thanks so much.
__________________
|
|
|
03-24-2005, 03:45 PM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
make some sort of check, which would say:
Code:
if number N=P != N+1=P+1 then Error
The only way I could see this sort of code running without alot of if/then/else clauses would be to make an array or better yet a dynamic array or even better, making it C++, with the use <vector> and any sort of mapping() function onto that.
|
|
|
03-24-2005, 08:16 PM
|
#7 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
got the code working
redhead,
thanks for all the work i got it working.
__________________
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:58 PM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|