như tít ạ, mọi người chỉ giúp em sai chỗ nào với.
Yêu cầu: Viết một chương trình để nhập dữ liệu vào một tập tin và in nó theo thứ tự ngược lại.
đây là code của e:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<fstream>
#include<stdlib.h>
int main()
{
FILE *fp;
char str [80];
int temp;
/* Writing to File Juice */
if ((fp = fopen("juice", "w+")) == NULL)
{
printf ("Cannot open file \n\n");
exit(1);
}
do
{
printf ("Enter a string: \n");
gets (str);
if(*str != '\n')
{ strcat (str, "\n"); /* add a new line */
fputs (str, fp);
}
} while (*str != '\n');
/* Reverse the string */
int n = strlen(str);
for(int i =0;i<n/2;i++)
{
temp = str[n-1-i];
str[n-1-i]=str[i];
str[i]=temp;
}
/*Print the reversed file */
printf ("\n\n Displaying Contents of File juice\n\n");
rewind(fp);
while (!feof(fp))
{
fgets (str, 80, fp);
printf ("\n%s", str);
}
fclose(fp);
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?