Hi,
i am working on Numerical Computation with C.... i have a data file which has two columns separated by a tab in between... it looks like
43.0000000000000 43.0000000000000
42.0000000000023 43.0000000000006
41.0000000000000 43.0000000000056
40.0000000000000 43.1999996948242
i have written this code which seems to work out smoothly...
#include <stdio.h>
main() {
FILE *file;
float nx[100],ny[100];
/* make sure it is large enough to hold all the data! */
int i,j;
file = fopen("INNERXY.txt", "r");
if(file==NULL) {
printf("Error: can't open file.\n");
return 1;
}
else {
printf("File opened successfully.\n");
i = 0 ;
while(!feof(file)) {
/* loop through and store the numbers into the array */
fscanf(file, "%f\t%f",&nx[i],&ny[i]);
i++;
}
printf("Number of numbers read: %d\n\n", i);
printf("The numbers are:\n");
for(j=0 ; j<i ; j++) { /* now print them out 1 by 1 */
printf("%0.13f\t%2.13f\n", nx[j],ny[j]);
}
fclose(file);
return 0;
}
}
i get an output which has been rounded off (the decimals).. and the output turns out to be
File opened successfully.
Number of numbers read: 4
The numbers are:
43.0000000000000 43.0000000000000
42.0000000000000 43.0000000000000
41.0000000000000 43.0000000000000
40.0000000000000 43.2000007629395
Note that the last number... is being rounded off...
Guys please help me out!!!
i dont want the numbers to be rounded off to the decimals.....
Thanks in advance....
--
SandyJain