fopen,fseek,fread,fclose

xiaoxiao2021-02-28  103

#include<stdio.h> #include<string.h> int main() {     FILE *file = fopen("text","a+");     if(NULL == file)     {         perror("fopen"); return 1;     }     char *str = "helloworld";     int count1 = fwrite(str, sizeof(str), strlen(str), file);     if(0 == count1)     {         perror("fwrite"); fclose(file); return 2;     }     fseek(file, 0, SEEK_SET);     char buffer[1024];     int count2 = fread(buffer,sizeof(char),  1024, file);     if(0 == count2)     {         perror("fread"); fclose(file); return 3;          }          printf("%s\n",buffer);     fclose(file);     return 0; }
转载请注明原文地址: https://www.6miu.com/read-44401.html

最新回复(0)