Solved

What is wrong? fgets

Posted on 1998-12-07
5
281 Views
Last Modified: 2010-04-15
I have a program what read lines from a file.
 ...
 if fgets (szBuffer, 82, FileIn)== NULL
     break;
  ...
  loops ( get next line)
   ...
when executing this program:
  MyProg MyTextFile ( param 1 is text file name)

It sometimes is okay and sometimes at the very last line of text it breaks with an error:
Line XX, token = 0: Out of Range
I did not put this debug mesg in, is it as compiler msg??
What do u think is the error?

Note: I hv a function that is called 'f2asc' that comverts my output file into binary code. It is called after reading the whole input file. Could it be this function???

Thanks!


0
Comment
Question by:Haho2
5 Comments
 
LVL 10

Expert Comment

by:rbr
ID: 1254940
Post more code pls. What does the f2asc function. Do you have the code for this function?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1254941
>> Could it be this function???
Probably.  Show the code
0
 
LVL 1

Expert Comment

by:sergelebel
ID: 1254942
-- f2asc --    you should comment out this function from your code and confirm a clean compile...the section which reads the text file appears to be correct...I have tried it myself with no errors... later!
0
 
LVL 4

Accepted Solution

by:
emmons earned 50 total points
ID: 1254943
Looks like you are trying to call strtok to break up the
line and for some reason you are doing it against a null
string (the end of file perhaps) and the result is an error.
This may be the result of not breaking out of the loop when
EOF is the only thing in the buffer.
Barring that, try posting more code.
0
 

Author Comment

by:Haho2
ID: 1254944
Yeah! It was the f2asc ...thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 129
negation in C function 14 132
Problem to ASCII 1 148
C Programming - If Statement 8 49
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now