// This code write random data into a file and every 5 seconds this //program send 5 seconds data into another file.
#include <HEADER FILES>
FILE *f1,*f2;
int main(int argc, char *argv[])
{
int i,j,m=0,n=0;
char buf[100];
f1 = fopen("//root//Example//output1.data", "wb+");
if(!f1) printf("File cannot open");
f2 = fopen("//root//Example//output2.txt", "wb");
if(!f2) printf("File cannot open");
srand ( time(NULL) );
for(i=1;i<=30;i++)
{
j=rand()%100;
fprintf(f1,"%d %d\n",i,j);
printf("%d %d \n",i,j);
sleep(1);
if(i%5 == 0)
{
fseek(f1,i*2-10, SEEK_SET );
m=fread(buf,2,10,f1);
n=fwrite(buf,2,10,f2);
printf("\nBuffer= %d %d\n",m,n); //Confirm Read and write
}
}
fclose(f2);
fclose(f1);
}
File "output1.data" showing the output:
1 37
2 52
3 16
4 98
6 13 //Don't have Number 5 data.
7 26
8 11
9 92
10 72
For "output2.txt" showing the output:
1 37
2 52
3 16
4 98
3 16 //Again start from line 3.
4 98
6 13
7 26
Question: Here I didn't get actual answer.Can anybody help me?
My expected answer is
For "output1.data" showing the output:
1 37
2 52
3 16
4 98
5 35 [5 th Second, So data will send 1-5 lines to "output2.txt" file]
6 13
7 26
8 11
9 92
10 72 [10 th Second, So data will send 6-10 lines to "output2.txt" file]
For "output2.txt" showing the output:
1 37
2 52
3 16
4 98
5 35
6 13
7 26
8 11
9 92
10 72
NB: This is not my homework.I am trying to solve this problem. 2 weeks always failed.If u have any new idea... please help me.
Thanks
Mostafijur