吴裕雄--天生自然C语言开发:文件读写

#include <stdio.h>
 
int main()
{
   FILE *fp = NULL;
 
   fp = fopen("/tmp/test.txt", "w+");
   fprintf(fp, "This is testing for fprintf...
");
   fputs("This is testing for fputs...
", fp);
   fclose(fp);
}
#include <stdio.h>
 
int main()
{
   FILE *fp = NULL;
   char buff[255];
 
   fp = fopen("/tmp/test.txt", "r");
   fscanf(fp, "%s", buff);
   printf("1: %s
", buff );
 
   fgets(buff, 255, (FILE*)fp);
   printf("2: %s
", buff );
   
   fgets(buff, 255, (FILE*)fp);
   printf("3: %s
", buff );
   fclose(fp);
 
}
size_t fread(void *ptr, size_t size_of_elements, 
             size_t number_of_elements, FILE *a_file);
              
size_t fwrite(const void *ptr, size_t size_of_elements, 
             size_t number_of_elements, FILE *a_file);
原文地址:https://www.cnblogs.com/tszr/p/10968732.html