Code:
#include<stdio.h>
#include<stdlib.h>
main()
{ int n1,n2,n3;
int h1,h2,h4,h5;
float h3,h6;
FILE *fp,*fp1,*fp2,*fp3;
fp=fopen("in.txt","r");
fp1=fopen("a.txt","w");
fp2=fopen("b.txt","w");
fp3=fopen("c.txt","w");
n1=n2=n3=0;
/* 11:57:25.138 0:00:00.020 */
while(fscanf(fp,"%d:%d:%f %d:%d:%f",&h1,&h2,&h3,&h4,&h5,&h6)!=EOF)
{
if(h6>00.020 && h6<=1.00)
{
fprintf(fp1,"%d:%d:%5.3f\n",h1,h2,h3);
n1=n1+1;
}
if(h6>1.00 && h6<=2.00)
{
fprintf(fp2,"%d:%d:%5.3f\n",h1,h2,h3);
n2=n2+1;
}
if(h5*h6>60)
{
fprintf(fp3,"%d:%d:%5.3f\n",h1,h2,h3);
n3=n3+1;
}
}
fprintf(fp1,"--------- %d",n1);
fprintf(fp2,"--------- %d",n2);
fprintf(fp3,"--------- %d",n3);
}
Hello everyone, the above is the code I was looking for. I would like to thank everyone who tried to help me. Especially Quzah and CommonTatter. Both provided working solutions. But I found the one by Quzah appropriate for my case.
There were two problems that I had to figure out, namely
1. Getting scanf the right format to read from the file supplied. This was solved by Quzah and CommonTatter.
2.Initially I had named my input file 21marSV19.txt and that somehow made the program useless. I while experimenting re-named it to in.txt, and suddenly things fell in place on their own. Keep it simple, is my lesson.
And like Quzah said...Doesn't work doesn't mean anything. Cheers!