Guys, I'm starting to learn C, and I'm trying to make a simple program to read input from another, and there is something strange. this is the input:
Code:
north: 7278678.49381985
south: 7276518.88888158
east: 733491.08009739
west: 730341.50485467
rows: 8
cols: 4
527
and this is the code
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
FILE *entrada;
char arquivo_in[30],arquivo_out[30];
double north_coord,south_coord,east_coord,west_coord,grid_ns,grid_ew;
int n_rows,n_cols,elev,i,j;
int main(int argc, char *argv[])
{
if(argc != 2)
{
printf("Input should be of the form \'svxdem [input] [output]\'");
return 1;
}
FILE *entrada = fopen(argv[1], "r");
if(entrada == NULL)
{
printf("Couldn't open %s", argv[1]);
return 1;
}
/* read ascii file limits */
fscanf(entrada,"north: %lf\n",&north_coord);
fscanf(entrada,"south: %lf\n",&south_coord);
fscanf(entrada,"east: %lf\n",&east_coord);
fscanf(entrada,"west: %lf\n",&west_coord);
fscanf(entrada,"rows: %d\n",&n_rows);
fscanf(entrada,"cols: %d\n",&n_cols);
fscanf(entrada,"%d",&elev);
/* calculate grid spacing */
grid_ns=(north_coord-south_coord)/n_rows;
grid_ew=(east_coord-west_coord)/n_cols;
printf("north: %7.8lf\n",north_coord);
printf("south: %7.8lf\n",south_coord);
printf("east: %6.8lf\n",east_coord);
printf("west: %6.8lf\n",west_coord);
printf("rows: %d\n",n_rows);
printf("cols: %d\n\n",n_cols);
printf("grid_ns: %lf\n",grid_ns);
printf("grid_ew: %lf\n\n",grid_ew);
printf("elev: %d\n",&elev);
printf("\n\n*** Done ***\n");
fclose(entrada);
return 0;
}
and this is the output:
Code:
north: 7278678.49381985
south: 7276518.88888158
east: 733491.08009739
west: 730341.50485467
rows: 24
cols: 35
grid_ns: 89.983539
grid_ew: 89.987864
elev: 134519392
*** Done ***
So, something is wrong, since it is reading 'elev' as a really bizarre value.
Do you see anything I missed?
tks