char c, cp;
FILE *input_file, *output_file;
input_file = fopen("d:\\input.txt","r");
output_file = fopen("d:\\output.txt", "w");
if(input_file==NULL){
printf("cannot open the input.txt file.");
exit(0);
}
if(output_file == NULL){
printf("cannot open the output.txt file.");
exit(0);
}
cp = fgetc(input_file);
while(cp!=EOF){
fputc(cp,output_file);
cp=fgetc(input_file);
}
c = fgetc(output_file);
while(c!=EOF){
printf("%c",c);
c=fgetc(output_file);
}
fclose(input_file);
fclose(output_file);
getch();
This is the code that I used while copying a text file. In the input.txt file I have written "Hello how are you".
After executing the code, the text "Hello how are you" is copied to the output.txt file but there are more than a hundred spaces after the copied text. After the code below the program is not working:
cp = fgetc(input_file);
while(cp!=EOF){
fputc(cp,output_file);
cp=fgetc(input_file);
}
Code below the above code is not working. What is happening? Please explain in detail. I am a beginner in C.