need some help with arrays
From: pillip (pillip_at_pillip.com)
Date: 02/26/04
- Next message: Nick Landsberg: "Re: 51MB size limit with fopen in append mode"
- Previous message: Guillaume: "Re: Efficiency of math.h"
- Next in thread: Leor Zolman: "Re: need some help with arrays"
- Reply: Leor Zolman: "Re: need some help with arrays"
- Reply: Mac: "Re: need some help with arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
}
- Next message: Nick Landsberg: "Re: 51MB size limit with fopen in append mode"
- Previous message: Guillaume: "Re: Efficiency of math.h"
- Next in thread: Leor Zolman: "Re: need some help with arrays"
- Reply: Leor Zolman: "Re: need some help with arrays"
- Reply: Mac: "Re: need some help with arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|