Solved

What is wrong? fgets

Posted on 1998-12-07
5
283 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

785 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