How do I open, read and write ASCII files?
Printable View
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.
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.
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.
Well, besides getc() and putc(), of course. :)Quote:
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.