E mới học đến tập tin, thì có viết 1 đoạn code đơn giản sau để in những gì có trong file INPUT.txt sang file OUTPUT.txt
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fileIn = fopen("INPUT.txt", "r");
if (!fileIn) {
printf("File not found.\n");
return 0;
}
FILE *fileOut = fopen("OUTPUT.txt", "w");
while (!feof(fileIn)) {
char str[50];
fgets(str, 50, fileIn);
fprintf(fileOut, "%s\n", str);
}
fclose(fileOut);
fclose(fileIn);
return 0;
}
Giả sử trong file INPUT.txt có:
Hello world
We don't talk anymore
Lorem ipsum dolor sit amet
thì trong file OUTPUT.txt cũng như vậy.
Nhưng sau khi compile & run đoạn code trên thì trong file OUTPUT.txt, mỗi dòng cách nhau 1 dòng, tức là:
Hello world
We don't talk anymore
Lorem ipsum dolor sit amet
Các pro có thể cho e hỏi vì sao ko ạ ? E nghĩ là do dòng fprintf(fileOut, "%s\n", str); có ký tự \n nhưng nếu có thì nó chỉ xuống 1 dòng thôi chứ sao 2 dòng nhỉ ??
Giúp e vs, cảm ơn các pro 
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?