C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2009, 01:53 PM   #16
Registered User
 
Join Date: Jul 2009
Posts: 15
Quote:
Originally Posted by MK27 View Post
Whoops!

You should throw a printf, including the return value of fscanf, into the while loop so you can see what actually is happening.
More trash I see. It seems like it's printing the address of the variable instead of printing the value of the variable. Is it not reading the file properly?
murjax is offline   Reply With Quote
Old 07-20-2009, 01:57 PM   #17
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Quote:
Originally Posted by murjax View Post
More trash I see. It seems like it's printing the address of the variable instead of printing the value of the variable. Is it not reading the file properly?
That's may well be because you're telling it to print the address of the variable. Make it print the value of the variable instead (like *EmployNum1, etc.).
tabstop is offline   Reply With Quote
Old 07-20-2009, 04:04 PM   #18
Registered User
 
Join Date: Jul 2009
Posts: 15
Quote:
Originally Posted by tabstop View Post
That's may well be because you're telling it to print the address of the variable. Make it print the value of the variable instead (like *EmployNum1, etc.).
That makes sense, except now I have the same problem I had before, printing the first 3 numbers correctly and then printing addresses for everything else.
murjax is offline   Reply With Quote
Old 07-20-2009, 04:25 PM   #19
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
Quote:
Originally Posted by murjax View Post
That makes sense, except now I have the same problem I had before, printing the first 3 numbers correctly and then printing addresses for everything else.
Is the return value of fscanf correct?
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 07-20-2009, 04:28 PM   #20
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Quote:
Originally Posted by murjax View Post
That makes sense, except now I have the same problem I had before, printing the first 3 numbers correctly and then printing addresses for everything else.
Did I see code and/or an input file before? And what was the return value from fscanf? And are you printing inside or outside the while loop? And does your format actually match the text file you're reading? (For instance, if any of the pay rates are more than 10.00, or there's a space between the pay rate and the exempt character, then the answer is "no".)
tabstop is offline   Reply With Quote
Old 07-20-2009, 04:37 PM   #21
Registered User
 
Join Date: Jul 2009
Posts: 15
Quote:
Originally Posted by MK27 View Post
Is the return value of fscanf correct?
It seems to be. Putting any other value in makes the printf statement print nothing.
murjax is offline   Reply With Quote
Old 07-20-2009, 04:44 PM   #22
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
Quote:
Originally Posted by murjax View Post
It seems to be. Putting any other value in makes the printf statement print nothing.
What I mean is something like this:
Code:
int retv;
retv=fscanf(....);
printf("fscanf scanned %d items", retv);
fscanf returns the number of items successfully read. So add that into your code and you will know whether it read 3 or 4 or 20. The condition of the while loop you posted earlier was just while(fscanf(...)) which is fine, but any positive number will pass that; it doesn't mean all 20 items were correctly scanned.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 07-20-2009, 04:48 PM   #23
Registered User
 
Join Date: Jul 2009
Posts: 15
Quote:
Originally Posted by tabstop View Post
Did I see code and/or an input file before? And what was the return value from fscanf? And are you printing inside or outside the while loop? And does your format actually match the text file you're reading? (For instance, if any of the pay rates are more than 10.00, or there's a space between the pay rate and the exempt character, then the answer is "no".)
There are spaces between every item in the file. Here are the contents of the file.

0101 41 8.11 Y 49
0722 32 7.22 N 40
1273 23 5.43 Y 39
2584 14 6.74 N 45
murjax is offline   Reply With Quote
Old 07-20-2009, 05:01 PM   #24
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Quote:
Originally Posted by murjax View Post
There are spaces between every item in the file. Here are the contents of the file.

0101 41 8.11 Y 49
0722 32 7.22 N 40
1273 23 5.43 Y 39
2584 14 6.74 N 45
Then don't lie to scanf -- your format must match the data, or else the attempt to read the formatted data will fail. Your format promises that there are no spaces (you get the numbers okay since %d and %f will skip spaces automatically -- but %c won't, and thus you are doomed to failure from then on). Put spaces in your format where spaces appear in your data.
tabstop is offline   Reply With Quote
Old 07-20-2009, 09:33 PM   #25
Registered User
 
Join Date: Jul 2009
Posts: 15
Quote:
Originally Posted by tabstop View Post
Then don't lie to scanf -- your format must match the data, or else the attempt to read the formatted data will fail. Your format promises that there are no spaces (you get the numbers okay since %d and %f will skip spaces automatically -- but %c won't, and thus you are doomed to failure from then on). Put spaces in your format where spaces appear in your data.
Ok now it works. Thanks.
murjax is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I have some questions :( geekrockergal C Programming 19 02-01-2009 09:44 AM
whats wrong with this? petedee C Programming 32 01-06-2004 10:28 PM
error in program???? SpEkTrE C Programming 5 11-24-2003 06:16 PM
Contest Results - May 27, 2002 ygfperson A Brief History of Cprogramming.com 18 06-18-2002 01:27 PM
Warnings, warnings, warnings? spentdome C Programming 25 05-27-2002 06:49 PM


All times are GMT -6. The time now is 01:37 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22