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 you up a concise little guide on it.
For reading, so long as it's not to be worked with purely as text, you want 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 commands 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 'C file IO tutorial' might be a good idea (of course I remember it after typing all of this).
-D/K
---
Borg Burgers: We do it our way; your way is irrelevant.
þ Synchronet þ Tinfoil Tetrahedron BBS
telnet://tinfoil.synchro.net