How do I open, read and write ASCII files?
How do I open, read and write ASCII files?
An ASCII file is only a text file with a specific character encoding. You can apply the C File I/O tutorial and read the file as a normal text file.
fopen()
fgets()
fclose()
Easy money.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Is there any other way to read/write ASCII files without using fopen and fclose?
Sure, use open and close, but I don't see why you'd want to. fopen and fclose are your standard methods of using files in C.
Quzah.
Hope is the first step on the road to disappointment.
fopen and fclose open and close files.
fread / fwrite / fgets / fputs / fgetc / fputc do the actual reading and writing.
Anything else is slipping into non portability.
I suppose you could open "/dev/hda" if you want to be extreme.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well, besides getc() and putc(), of course.Anything else is slipping into non portability.
getc() and putc() are equivalent to fgetc() and fputc(), but are usually implemented as macros instead of functions; so the might be slightly faster, but don't pass them an argument like "c++", because it could be evaluated several times.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.