Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Standard C, C++
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-24-2005, 11:56 AM   #1 (permalink)
etorres
Registered User
 
Join Date: Mar 2005
Posts: 6
etorres is on a distinguished road
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.
etorres is offline   Reply With Quote
Old 03-24-2005, 02:06 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-24-2005, 02:29 PM   #3 (permalink)
etorres
Registered User
 
Join Date: Mar 2005
Posts: 6
etorres is on a distinguished road
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.
__________________
etorres is offline   Reply With Quote
Old 03-24-2005, 03:17 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-24-2005, 03:34 PM   #5 (permalink)
etorres
Registered User
 
Join Date: Mar 2005
Posts: 6
etorres is on a distinguished road
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.
__________________
etorres is offline   Reply With Quote
Old 03-24-2005, 03:45 PM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-24-2005, 08:16 PM   #7 (permalink)
etorres
Registered User
 
Join Date: Mar 2005
Posts: 6
etorres is on a distinguished road
got the code working

redhead,

thanks for all the work i got it working.
__________________
etorres is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Techniques for improving ANSI C code asc01001 Standard C, C++ 1 03-18-2005 11:26 PM
Cisco Code breaking sde Code Newbie News 0 05-21-2004 07:10 AM
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM
Starting out with C anon C 0 02-24-2003 01:06 PM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 11:58 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle