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. 8 2327
"Joriveek" <no****@please.com> wrote in message
news:dg**********@reader01.news.esat.net... 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
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?"
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.
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr... 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?"
Joriveek wrote: 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.]
--
Chris "electric hedgehog" Dollin
Logic is rational /re/construction. Life is construction.
"Joriveek" <no****@please.com> wrote:
Please don't top-post. Fixed. "Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr.. . 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.
<snip> Read the FAQ, please.
http://www.eskimo.com/~scs/C-faq/faq.html
Did you read the FAQ already?
You should use a reading I/O function (fgetc(), fgets(), fread() etc.) and test the return value to detect the end of the reading. 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
--
Irrwahn Grausewitz (ir*******@freenet.de)
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
Thanks I sorted out
"Irrwahn Grausewitz" <ir*******@freenet.de> wrote in message
news:l6********************************@4ax.com... "Joriveek" <no****@please.com> wrote:
Please don't top-post. Fixed.
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr. .. 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. <snip> Read the FAQ, please.
http://www.eskimo.com/~scs/C-faq/faq.html Did you read the FAQ already? You should use a reading I/O function (fgetc(), fgets(), fread() etc.) and test the return value to detect the end of the reading. 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 -- Irrwahn Grausewitz (ir*******@freenet.de) 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
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."
"Joriveek" <no****@please.com> writes: 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.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wolfgang Werners-Lucchini |
last post by:
Hallo!
The code here outputs '0'. Why?
----------------------------
$filename = "test.dat";
if (!file_exists($filename)) {
touch($filename); // Create blank file
chmod($filename,0666);
}...
|
by: Mantorok Redgormor |
last post by:
My professor that teaches C says that using feof to test if EOF is
reached while using a function like fgets on a file is okay. but i've
been told elsewhere that it is not okay. what is the case...
|
by: ehui928 |
last post by:
I use the following program to read some strings from an inupt file,
and print them on the standard output.
But the last string in the input file always printed twice, what is
the reason and how...
|
by: rCs |
last post by:
Which of the following two approaches is preferred (and why)?
int c;
do {
...
c = getchar();
} while (c != EOF);
- or -
|
by: ericunfuk |
last post by:
If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file...
|
by: 2005 |
last post by:
context of a C program reading from a file?
I know its end of file but ...not sure?
|
by: kindrain |
last post by:
the code checks whether a.txt has exact the same lines, then write
different lines into b.txt
Here it is:
(before that ,you should creat a.txt)
----------------------
#include<stdio.h>...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |