C language : write/read for file

Open a file

FILE *fopen( const char * filename, const char * mode );

Close a file

int fclose( FILE *fp );

Write to a file

You’d better write strings to a file instead of directly writing integer,float or something else.

You can first make the number into a string.

sprintf(char *p,"%format",number);

Then you can write strings to the file one by one.

fputs(char *p,FILE *fp);
//You write one character for one time

Read from a file

fscanf(FILE *fp,"%formant",char *p)
//You read one character for one time

你可能感兴趣的:(C)