fopen fscanf fprintf函数示例
示例如下:
#include <stdio.h>int main ()
{char name [20];int age, length;FILE *fp;fp = fopen ("test.txt","w+");fprintf (fp, "%s %d","Fresh2refresh",5000);length = (int)ftell(fp); // Cursor position is now at the end of file/* You can use fseek(fp, 0, SEEK_END); also to move thecursor to the end of the file */rewind (fp); // It will move cursor position to the beginning of the filefscanf (fp, "%s", name);//这两个fscanf是有顺序的,先age再name就会读不到age,因为指针在文件开始处fscanf (fp, "%d", &age);fclose (fp);printf ("Name: %s \n Age: %d \n",name,age);printf ("Total number of characters in file is %d\n", length);return 0;
}
#fread函数