I wrote this program to read a paragraph written in a file in a text file and copy it to another file. The program worked ok but when I open the copy file it had a garbage character in the end. I attach my source code below. I keep having the "ÿ" character at EOF. Can anyone help me with this?
void main()
{
FILE *fp;
char ch = NULL;
fp = fopen("vanban.txt", "r");
if (fp != NULL)
{
printf("Mo File thanh cong!\n");
printf("Doc File thanh cong!\n");
char ch = NULL;
FILE *fp1;
fp1 = fopen("vanban1.txt", "w");
do
{
if (ch <= 255 && ch >= 0)
{
ch = fgetc(fp);
fputc(ch, fp1);
}
} while (ch != EOF);
fclose(fp1);
}
else
{
printf("FIle khong mo duoc hoac khong ton tai.\n");
}
fclose(fp);