橘子味的心
标题:C库函数 fread()

C库函数 fread()

#include <stdio.h>

#include <string.h>



int main () {

   FILE *fp;

   char c[] = "this is codingdict";

   char buffer[100];



   /* Open file for both reading and writing */

   fp = fopen("file.txt", "w+");



   /* Write data to the file */

   fwrite(c, strlen(c) + 1, 1, fp);



   /* Seek to the beginning of the file */

   fseek(fp, 0, SEEK_SET);



   /* Read and display data */

   fread(buffer, strlen(c)+1, 1, fp);

   printf("%s\n", buffer);

   fclose(fp);



   return(0);

}

目录

分类