feof

J

Joriveek

Hi,

If I use while(!feof( FileRead )), it reads each line from my input file
until it encounters an empty space or so,

but when I have empty spaces within one line, it is not working, it is only
reading until it finds the first empty space. But I want to read all line
and then go to next line when the characters start from \n (second line),

hw can i read this?

Thanks
J.
 
M

Mike Wahler

Joriveek said:
Hi,

If I use while(!feof( FileRead )), it reads each line from my input file
until it encounters an empty space or so,

No, 'feof()' does not read anything. It simply tells you
whether the last input request for the stream denoted by
'FileRead' tried to read *past* end the of the file.
but when I have empty spaces within one line, it is not working, it is
only reading until it finds the first empty space. But I want to read all
line and then go to next line when the characters start from \n (second
line),

hw can i read this?

Use 'fgets()'. Be sure to test its return value before
proceeding with further i/o on the stream (See its
documentation for the possible return values and their
meanings).

Also see the C FAQ for why you should not test for EOF
before reading, but *after*.
http://www.eskimo.com/~scs/C-faq/faq.html
(See section 12)

-Mike
 
E

Emmanuel Delahaye

Joriveek wrote on 13/09/05 :
If I use while(!feof( FileRead )), it reads each line from my input file
until it encounters an empty space or so,

Non. It will probably acts like an infinite loop, unless you provide a
read function. But even in this case, the behaviour is wrong, because
feof() has a meaning only after an end of reading has occur. feof() and
ferror() can be used (rarely, actually) to determine the cause of the
stop.
but when I have empty spaces within one line, it is not working, it is only
reading until it finds the first empty space. But I want to read all line and
then go to next line when the characters start from \n (second line),

hw can i read this?

Read the FAQ, please.

http://www.eskimo.com/~scs/C-faq/faq.html

You should use a reading I/O function (fgetc(), fgets(), fread() etc.)
and test the return value to detect the end of the reading.


--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

I once asked an expert COBOL programmer, how to
declare local variables in COBOL, the reply was:
"what is a local variable?"
 
J

Joriveek

Thanks fgets() is of a great help, but it is only reading first line from my
input file, what should I make this to read all other lines?

Thanks
J.
 
C

Chris Dollin

Joriveek said:
Thanks fgets() is of a great help, but it is only reading first line from
my input file, what should I make this to read all other lines?

Call it again?

[It's very hard to see what you're doing wrong, if we can't see what
you're doing at all.]
 
I

Irrwahn Grausewitz

Please don't top-post. Fixed.

Did you read the FAQ already?
Thanks fgets() is of a great help, but it is only reading first line from my
input file, what should I make this to read all other lines?

No, you didn't read the FAQ. Sigh.

General answer:
get yourself a decent textbook on C, I recommend "The C Programming
Language" by Brian W. Kernighan and Dennis M. Ritchie, 2nd edition

Specific answer:
use a loop

Oh, and read the FAQ, please.

Best regards
 
J

Joriveek

Thanks I sorted out


Irrwahn Grausewitz said:
Please don't top-post. Fixed.


Did you read the FAQ already?


No, you didn't read the FAQ. Sigh.

General answer:
get yourself a decent textbook on C, I recommend "The C Programming
Language" by Brian W. Kernighan and Dennis M. Ritchie, 2nd edition

Specific answer:
use a loop

Oh, and read the FAQ, please.

Best regards
--
Irrwahn Grausewitz ([email protected])
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc
 
E

Emmanuel Delahaye

Joriveek wrote on 14/09/05 :
Thanks fgets() is of a great help, but it is only reading first line from my
input file, what should I make this to read all other lines?

Consider a code structure like while()...

Time to open a C-book...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
 
K

Keith Thompson

Joriveek said:
Thanks I sorted out

Great.

Again, please don't top-post. Your response belongs below any quoted
text, and you should trim anything that isn't relevant. The idea is
that each followup should be readable by itself, from top to bottom.
See nearly any article this newsgroup for an example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top