I am writing a code which reads only the first line of the text file then outputs it to new text file. I am getting this error named "Segmentation Fault". I cannot understand the reason behind this error.
FILE *inputFile = fopen("input1.txt", "r" );
FILE *outputFile = fopen("output1.txt", "w" );
int i=0;
char line [128][10];
if ( inputFile != '\0' ) {
while ( fgets ( line[i], sizeof line, inputFile ) != '\0' ) {
i++;
fclose ( inputFile );
}
}
for(int j=0;j<i;j++) {
printf("%s",line[j]);
fprintf(outputFile,"%s",line[j]);
}
Text File Contains 1)Today is Tuesday 2) Tomorrow is Wednesday .... so on (upto 10 lines)
I am trying to only read the 1st line then display that immediately to stdout.Ignoring all other lines below.