need some help with arrays

From: pillip (pillip_at_pillip.com)
Date: 02/26/04


Date: Thu, 26 Feb 2004 01:20:39 GMT

I am trying to use fopen and fget to input two files and then output them
into one file. Each input file has two columns and 20 rows, however since
the first column in each input file is same ( numbers 0...19), i want the
output file to have 3 columns and 20 rows. Right now i am using a one
dimensional array "array1[SIZE]" to input each file:, and the output file
has 2 columns and 42 rows.

#include <stdlib.h>
#include <stdio.h>

#define SIZE 20

main()
{
 char array1[SIZE], array2[SIZE];
      FILE *fp;

     if ( (fp = fopen("1a.data", "r")) == NULL)
       {
          fprintf(stderr, "Error opening file.");
          exit(1);
       }

       while ( !feof(fp) )
       {
          fgets(array1, SIZE, fp);
          printf("%s",array1);
       }
  fclose(fp);

 printf("\n\n");

 if ( (fp = fopen("1b.data", "r")) == NULL)
       {
          fprintf(stderr, "Error opening file.");
          exit(1);
       }

       while ( !feof(fp) )
       {
          fgets(array2, SIZE, fp);
          printf("%s",array2);
       }
  fclose(fp);

return(0);
}



Relevant Pages

  • Re: Plot lines from file through points undefined by ternary operator
    ... >I'm trying to plot data from a file. ... >input file. ... will filter out anything that has a leading 0 or minus sign. ... If you have to deal with fractions in the first column ...
    (comp.graphics.apps.gnuplot)
  • Re: the smallest value in a row
    ... and I would like to get an output file as following: ... the first column = the first column; ... the fourth or the last column (input file) ...
    (comp.lang.awk)
  • the smallest value in a row
    ... and I would like to get an output file as following: ... the first column = the first column; ... the second column =the smallest values of the second - ... the fourth or the last column (input file) ...
    (comp.lang.awk)