Solved

What is wrong? fgets

Posted on 1998-12-07
5
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

734 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