I am writing a code to read file and output stuff for two files and combine them together... Don't know why they read good at the first file but wit the same code , it didn't show up for the second file
Please help
Thanks
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#include <iostream>
int main() {
FILE *file;
int i;
int j=0;
char fileparam[16] ;
char arraytotal [200];
int start =0 ;
int k = 0 ;
if(sprintf(fileparam, "in0.dat",i) )
{
file = fopen(fileparam,"r");
if(file==NULL)
{
printf("Error: %s does not exist\n",fileparam);
}
else
{
printf("%s was opened successfully.\n", fileparam);
printf("Good\n");
for ( k = start; k <sizeof arraytotal; k++)
{
arraytotal[k] = (char)fgetc(file);
printf("%c",arraytotal[k]);
start++;
} // end for
}
}
if(sprintf(fileparam, "in1.dat",i) )
{
file = fopen(fileparam,"r");
if(file==NULL)
{
printf("Error: %s does not exist\n",fileparam);
}
else
{
printf("%s was opened successfully.\n", fileparam);
printf("Good\n");
for ( k = start; k <sizeof arraytotal; k++)
{
arraytotal[k] = (char)fgetc(file);
printf("%c",arraytotal[k]);
start++;
} // end for
}
} // end if
printf("Final Result is \n");
for ( k = 0; k <sizeof arraytotal; k++)
{
printf("%c",arraytotal[k]);
} // good code for open file
// the rest of process related to the file are trim
fclose(file);
system("pause");
return 0;
}