Solved

What is wrong? fgets

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
memory mapped I/O query 6 142
SQL Statment to match two tables in c# 6 77
Grammars for C C++ and java 1 113
c++ getting the first 10 characters of a char* string 11 90
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…
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…
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 and use conditional statements in the C programming language.

911 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

19 Experts available now in Live!

Get 1:1 Help Now