#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;
}
#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;
}