求解 为什么不能跳转到第二个循环
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{FILE *fp_read;
FILE*fp_write;
char fname[256];
char desname[256];
char t;
int len;
A:printf("Please input source:\n");
scanf("%s",fname);
fp_read=fopen(fname,"rb");
if(fp_read==NULL)
{printf("can't open source file!\n");
goto A;
}
B:
printf("Please input destination:\n");
scanf("%s",desname);
fp_write=fopen(desname,"wb");
if(fp_write==NULL)
{
printf("can't find destination!\n");
goto B;
}
while(true)
{fread(&t,1,1,fp_read);
if(feof(fp_read))
break;
fwrite(&t,1,1,fp_write);
}
ftell(fp_write);
fseek(fp_write,0L,SEEK_END);
len =ftell(fp_write);
printf("%d byte<s> copied!\n",len);
fclose(fp_write);
fclose(fp_read);
printf("Copying...\n");
printf("done!\n");
getch();
return 0;
}
[解决办法]
- C/C++ code
fp_read=fopen(fname,"rb");if(fp_read==NULL){ printf("can't open source file!\n"); goto A;}printf("open source file OK!\n");//建议楼主在这儿加个打印,看看if(fp_read==NULL)有没有不成立B:
[解决办法]
你试试这么修改
- C/C++ code
B: printf("Please input destination:\n"); scanf("%s",desname); fp_write=fopen(desname,"r+"); if(fp_write==NULL) { printf("can't find destination!\n"); goto B; } 