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
Solved

What is wrong? fgets

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

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…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

808 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