-
Saving to a file!
hello! i was wonderin if any1 could help me with saving the program to a named file. i have a football league table, and i would like to save it so the league table is still the same when i load it! id like the user to enter the name of the file that it is going to be saved to! plz help!!! thanx!
-
You need to open the file using fopen() and the "w" mode, then you can write to the file just like you write to the screen. When you're done, be sure to close the file with fclose(). It's that easy. :)
Code:
#include <stdio.h>
int main( void ) {
FILE *fp = fopen( "file.txt", "w" );
if ( fp ) {
fprintf( fp, "writing to the file\n" );
fclose( fp );
}
return 0;
}
-
ok thanx!! im just havin a little truble understandin how it works =( . i would like to have in the menu the option to "save table" and another option to "load table". so i would have somthing like:
Code:
int savetable():
{
}
and
int loadtable():
{
}
what would the code be in each of the above?? thanx!!
-
I'm not going to write your program for you. :p Try writing some little test programs with the one I gave you as an example and figure out how it works. It really helps if you have a book or a good tutorial. I think cprogramming.com has a tutorial on working with files.
-