#include <stdio.h>
#include <string.h>
int main()
{
FILE *file = fopen("./text1", "a+");
if (NULL == file)
{
perror("fopen");
fclose(file);
return 1;
}
char* str = "helloworld";
int fd = fwrite(str, sizeof(char), strlen(str), file);
if (-1 == fd)
{
perror("fwrite");
fclose(file);
return 1;
}
fseek(file, 0, SEEK_SET);//设置文件指针指向的位置为文件起始的位置
char array[1024] = {0};
fd = fread(array, sizeof(char), 1024, file);
if (-1 == fd)
{
perror("fread");
fclose(file);
return 1;
}
printf("%s\n", array);
return 0;
}