1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/******PROGRAM TO READ THE FILE dataset.txt and PRINT output******/
/*****************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *lon,*lat,*jan,*feb,*mar,*apr,*may,*jun,*jul,*aug,*sep,*oct,*nov,*dec;
float v,l,j,f,mr,a,my,jn,jl,ag,s,o,n,d;
char line[300];
FILE *fp = fopen("dataset.txt","r");
FILE *fo = fopen("new.txt","w");
fprintf(fo,"Lat \t Lon \t Jan \tFeb \tMar \tApr \tMay \t Jun \t Jul \t Aug\t Sep \t Oct \t Nov \tDec\n",line);
while(fgets(line,sizeof line, fp)!= NULL)
{
lat=strtok(line," ");
v=atof(lat);
if (v>10 && v<35)
{
lon=strtok(NULL," ");
l=atof(lon);
if(l>65 && l<100 )
{
jan=strtok(NULL," ");
j=atof(jan);
feb=strtok(NULL," ");
f=atof(feb);
mar=strtok(NULL," ");
mr=atof(mar);
apr=strtok(NULL," ");
a=atof(apr);
may=strtok(NULL," ");
my=atof(may);
jun=strtok(NULL," ");
jn=atof(jun);
jul=strtok(NULL," ");
jl=atof(jul);
aug=strtok(NULL," ");
ag=atof(aug);
sep=strtok(NULL," ");
s=atof(sep);
oct=strtok(NULL," ");
o=atof(oct);
nov=strtok(NULL," ");
n=atof(nov);
dec=strtok(NULL," ");
d=atof(dec);
fprintf(fo,"%.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f %.04f\n",v,l,j,f,mr,a,my,jn,jl,ag,s,o,n,d);
}
}
}
fclose(fp);
fclose(fo);
return (0);
}
|