Could somebidy show me how to read and write to files in C and also explain the code as well as that is very important.
Re: How to read and write to files in C?
By: Deavmi to All on Wed Nov 25 2015 14:04:36
Could somebidy show me how to read and write to files in C and also explain the code as well as that is very important.
First command you need to learn (and I believe these are all in stdio.h and/or stdlib.h) is 'fopen()'... did I say command I meant function... If you're on a linux system that has the right manpages 'man fopen' will bring up a concise little guide on it.
For reading, so long as it's not to be worked with purely as text, you wan to look up next 'fread()', then for writing it's 'fwrite()'. So man fread & man fwrite to see those.
C is a stickler, too. Make sure you use fclose() when you're done on that filehandle, too.
If you're not on a linux system you should be able to google these command along with a capital 'C' and find either the appropriate manpages online or else a good tutorial that covers the applicable material. In fact googling file IO tutorial' might be a good idea (of course I remember it after typing all of this).
-D/K
Sysop: | Tandy |
---|---|
Location: | New York, USA |
Users: | 15 |
Nodes: | 13 (0 / 13) |
Uptime: | 14:41:59 |
Calls: | 335 |
Messages: | 112,959 |