okay. i will try this.
i've written a code like following:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
FILE *in, *out,*in2;
char ch,str[10],str1[10],str2[10],str3[10];
char *rdf,*wdf,*rdf2;
float svp1,svp2,svp3;
float avp1,avp2,avp3;
double exsvp1,exsvp2,exsvp3;
char rh1[10],rh2[10],rh3[10];
clrscr();
rdf="A:\\cvp.csv";
wdf="A:\\a.csv";
in = fopen(rdf,"rb");
// in2 = fopen(rdf2,"rb");
out = fopen(wdf,"w");
if(in == NULL)
{
printf("Cannot open input file.\n");
exit(1);
}
if(out == NULL)
{
printf("Cannot open output file.\n");
exit(1);
}
while(fscanf(in,"%s %s %s %s %s %s\n,",&str1,&str2,&str3,&rh1,&rh2,&rh3)>0 )
{
svp1 = ((atof(str1) * 21.4) + 494.41 ) / (atof(str1) + 273.15);
svp2 = ((atof(str2) * 21.4) + 494.41 ) / (atof(str2) + 273.15);
svp3 = ((atof(str3) * 21.4) + 494.41 ) / (atof(str3) + 273.15);
printf("%f,%f\n",svp1,svp2);
exsvp1 = exp(svp1);
exsvp2 = exp(svp2);
exsvp3 = exp(svp3);
avp1= (atof(rh1)/100) * exsvp1;
avp2= (atof(rh2)/100) * exsvp2;
avp3= (atof(rh3)/100) * exsvp3;
fprintf(out,"%f %f %f %f %f %f \n",exsvp1,exsvp2,exsvp3,avp1,avp2,avp3);
printf("%f %f %f",avp1,avp2,avp3);
}
printf("\nFile has successfully written");
fclose(in);
fclose(out);
getch();
getch();
return 0;
}
this works properly in turbo c..
when i deal with linux it says segmentation fault.
i've deleted clrcsr() n getch()..
problem is the first line of my csv file which is :
AGRO_ST1, AGRO_ST2, AGTO_ST3,..
n rest all line is int/float ...
so if i delete first line from csv file then it works properly.
otherwise gives error.
i've some idea of solution using sscanf .. but how i don't know..!!