69,370
社区成员
发帖
与我相关
我的任务
分享
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp = NULL;
char cmd[256] = "\0";
int ret = 0;
int tmp = 0;
if((fp=fopen("/tmp/host_info_p_phy","r"))==NULL)
{
printf("File /tmp/host_info_p_phy not exist!\n");
printf("let's make it!\n");
snprintf(cmd,256,"touch /tmp/host_info_p_phy");
system(cmd);
if((fp=fopen("/tmp/host_info_p_phy","w"))==NULL)
{
printf("Error,no file!\n");
return -1;
}
fprintf(fp,"%d",tmp);
fflush(fp);
}
printf("Position:%d\n", ftell(fp));
rewind(fp);
printf("Position:%d\n", ftell(fp));
fread(&ret,sizeof(int),1,fp);
printf("ret is : %d\n", ret);
fscanf(fp,"%d", &ret);
printf("ret is : %d\n", ret);
fclose(fp);
return 0;
}