I'm teaching myself C programming for a personal project, and when I run
this program, the file (array1.cpp) is sent to the destination file
(LIST E.cpp) but not the output of the array. I tried (array1.exe) but
sent garbled dribble. I'm only trying to send the output of the array to the destination file (LIST E.ccp). Can anyone help, been at this for weeks? Thanx Rossco
Code:
#include <stdio.h>
#include <cstdlib>
main()
{
int list[3][6] = { 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18};
int i, j;
i = 0;
for(j = 0; j < 6; j++)
printf( "%4d", list[i][j]);
printf( "\n");
for( j = 0; j < 12; j++) {
if((j>4)&&(j<11))
continue;
printf( "%4d", list[i][j]);}
printf( "\n");
for(j=0; j<18; j++) {
if((j>4) && (j<17))
continue;
printf( "%4d", list[i][j]); }
printf( "\n");
enum {SUCCESS, FAIL};
void CharReadWrite(FILE *fin, FILE *fout);
// defines two file pointers
FILE *fptr1, *fptr2;
char filename1[] = "LIST E.cpp"; //array 1 initiated with filename
char filename2[] = "array1.cpp"; //writes to the above file
int reval = SUCCESS;
if((fptr1 = fopen(filename1, "w")) == NULL){
printf( "Cannot open: %s\n", filename1);
reval = FAIL;
}
else if ((fptr2 = fopen(filename2, "r")) == NULL){
printf( "Cannot open %s\n", filename2);
reval = FAIL;
} else {
CharReadWrite(fptr2, fptr1);
fclose(fptr2);
fclose(fptr1);
}
system ("PAUSE");
return reval;
}
void CharReadWrite(FILE *fin, FILE *fout)
{
int c;
while((c=fgetc(fin)) != EOF) {
fputc( c, fout);
putchar(c);
}
}