#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main() {
int ret = 0;
char buf[] = “mr liu yyds”;
char readbuf[128] = {0};
FILE *fp;
fp = fopen(“fopen.txt”, “w+”);
if (NULL == fp)
{
printf(“fopen fail\n”);
return 0;
}
if (1 != fwrite(buf, strlen(buf), 1, fp))//fputc fputs
{
printf(“fwrite fail\n”); goto error;
}
if (fseek(fp, 0, SEEK_END))
{
printf(“fseek fail\n”); goto error;
}
ret = ftell(fp);
if (!ret)
{
printf(“ftell fail\n”); goto error;
}
fseek(fp, 0, SEEK_SET);
if (0 == fread(readbuf, ret, 1, fp))
{
printf(“fread fail\n”); goto error;
}
printf(“readbuf[%s]\n”, readbuf); error:
fclose(fp);
return 0; }
03-16
1356