#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char**argv)
{
FILE *fp = NULL;
fp = fopen("/tmp/exercise", "w+");
if (fp == NULL)
{
printf("open error line=%d file%s",__LINE__,__FILE__);
}
char s[128] = {"score is"};
int i = 601;
fprintf(fp, "my %s",s);
fputc(':',fp);
fprintf(fp,"%d\n",i);
fputs("that is good",fp);
fclose(fp);
}
#include<iostream>
using namespace std;
#include <stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
int main(int argc,char**argv)
{
FILE *fp = NULL;
char buff[1024] = {0};
int i =0;
while(1)
{
fp = fopen("/tmp/exercise","r+");
if(fp == NULL)
{
printf("fopen error\n");
sleep(3);
continue;
}
if (fgets(buff, 13, fp) != NULL)
{
cout<<"buff: "<<buff<<endl;
}
fscanf(fp,"%d",&i);
cout<<"i="<<i<<endl;
putchar(fgetc(fp));
fgets(buff, 13, fp);
cout<<"buff: "<<buff<<endl;
fclose(fp);
sleep(3);
}
return 0;
}