i'm working on this program to 'read an array(int and float values) from a file and then print it out on the screen'....the i/p data file is looks like this

#lat lon B s date X v
60.97 56.10 26.50 33.389 03 07 02 24.00 4
60.36 53.58 28.90 35.731 06 07 02 29.04 4
60.17 55.16 28.50 35.180 07 07 02 99.99 4
60.15 55.03 28.40 35.435 22 07 02 28.59 5

there are about 800 rows of data.

the code i'm writing is part of a bigger task but i've broken it down to simpler ones.
my code compiles with no errors but doesn't print the array on the screen. pls help. i'm working on a ubuntu system.

1 #include<stdio.h>
2 #include<stdlib.h>
3 main()
4 {
5 FILE *fp1;
6 double lat[500],lon[500],bsst[500],sss[500],xsst[500];
7 int dd[500],mm[500],yy[500],voy[500];
8 int row=0,col,fields,entries,i;
9  
0 fp1=fopen("kl-sss.dat","r");
11
12  while(feof(fp1)==0)
13  
14 {
15   //for(row=0;row<486;row++)
16      fscanf(fp1,"%lf\t%lf\t%lf\t%lf\t%d\t%d\t%d\t%lf 
\t%d\t",&lat[row],&lon[row],&bsst[row],&sss[row],&dd[row],&mm[row],&yy[row],&xsst[row],&voy[row]);
17      row++;
18  }  
19
20  
21 for(i=0;i<2;i++)
22    { printf("%lf\t%lf\t%lf\t%lf\t%d\t%d\t%d\t%lf\t%d\n",lat[i],lon[i],bsst[i],sss[i],dd[i],mm[i],yy[i],xsst[i],voy[i]);}
 
23  fclose(fp1);
24 }

Recommended Answers

All 5 Replies

If the rows of data are consistent, why not create a structure to represent a row and have an array of structures.

works for me.

hey...i figured it out....the program runs if i remove the header from the input file.....but is there any command in C to tell the program to skip a certain number of lines....like in this case the header line.

Sure. It's called an input command, like fgets()

thanx waltP :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.