![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Sep 2005
Posts: 50
Rep Power: 0
![]() |
bug that i can't find
this works fine but it has a problem that it writes an extra char "ÿ" in end of the copied file then exits.
#include<conio.h> #include<stdio.h> #include<stdlib.h> using namespace std; int main() { int a,b; char ch; FILE *fp,*cfp; //cheak file exists if((fp=(fopen("sunny.txt","r")))==NULL) { printf("Were the fuck is file"); } //cheak that file has created if((cfp=fopen("sunny.out","w"))==NULL) { printf("window sucks"); } while(feof(fp)==0) { ch=fgetc(fp); fputc(ch,cfp); printf("%c",ch); } fclose(fp); fclose(cfp); } |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,203
Rep Power: 5
![]() |
Please read the posts on how to post questions. In particular, learn how to use code tags.
It's not usually a good idea to have a loop of the form while (feof(fp) == 0)
{
ch = fgetc(fp);
fputc(ch, cfp);
}You might change your code to this .... while (feof(fp) == 0)
{
ch = fgetc(fp);
if (ch != EOF) fputc(ch, cfp);
}while ((ch = fgetc(fp)) != EOF)
{
fputc(ch, cfp);
} |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Sep 2005
Posts: 50
Rep Power: 0
![]() |
thanks grumpy
i understand the bug and solution |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|