#include #include int main() { int i_vec[20]; double d_vec[20]; const int N_LINES = 20; int line; /* fp is a pointer to the object controlling the stream. */ FILE *fp; /* Open the file, named infile, using read-only mode. */ if ((fp = fopen("infile", "r")) == NULL) { printf("Problems opening file infile.\n"); exit(1); } for(line = 0; line < N_LINES; line++) fscanf(fp, "%d %lf", &i_vec[line], &d_vec[line]); /* Close file. */ fclose(fp); /* ------------------------------------------------ If we don't know the number of lines in the file we can do like this. Note that i_vec and d_vec MUST have room for the elements. */ if ((fp = fopen("infile", "r")) == NULL) { printf("Problems opening file infile.\n"); exit(1); } line = 0; while( fscanf(fp, "%d %lf", &i_vec[line], &d_vec[line]) != EOF) line++; fclose(fp); printf("# of lines = %d\n", line); /* Start computing ... */ return 0; }