how to read 10 lines from a 200 lines file and write to a new file??

how to read 10 lines from a 200 lines file and write to a new file??

Post by Emmanuel D » Tue, 29 Jul 2003 02:21:03



Sure. Use the FILE functions (fopen(), fgets() etc.)

It's time to buy a C-book. There are good references in the FAQ.

Note : Please don't ask anything here about C++. C++ *is not* C at all. Try



--
-ed- XXXX@XXXXX.COM [remove YOURBRA before answering me]
The C-language FAQ: http://www.yqcomputer.com/ ~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.yqcomputer.com/ ~rumeau/fclc/
 
 
 

how to read 10 lines from a 200 lines file and write to a new file??

Post by Joe Wrigh » Tue, 29 Jul 2003 05:50:31


I'm sorry to be the one to tell you but you shouldn't post this kind of
'stuff' here. First, you open the input file in "w" mode, removing it.
Then you pretend to read it. The second argument to fgets, 'sizeof line
- 1' is wrong. Figure it out.

Most of us here, even the guru's have been bitten by this kind of thing
more than once. The first rule is 'Be Quiet' and let the next guy screw
up the response. The next rule is 'Compile it and Test it before you
Post it.'

--
Joe Wright mailto: XXXX@XXXXX.COM
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

 
 
 

how to read 10 lines from a 200 lines file and write to a new file??

Post by airi » Tue, 29 Jul 2003 12:57:17


A main() wrapper would help :-)


The p is redundant, as is the assignment which you go on to clober.
Probably better to make line static, for implementations with very
small stack spaces.


You can pass the full buffer width to fgets()...

if (fgets(line, sizeof line, fin))


You should test fin and fout *before* calling fgets().

Peter