以下是源代码,实现的结果是,磁盘中的信息是隔一个字符复制的,不知道为什么,求指点,谢谢。
#include
#include
#include
main()
{
FILE *fp;
FILE *fp1;
char ch;
char filename[10];
char filename1[10];
char filepath[50];
char filepath1[100];
printf("give a file a filename: ");
scanf("%s",filename);
sprintf(filepath,"/socketTest/photo/%s",filename);
if((fp=fopen(filepath,"w+"))==NULL)
{
printf("cannot open the file <%s>\n",filename);
return 0;
}//if
ch=getchar();
printf("please input:\n");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
ch=getchar();
}//while
fclose(fp);
printf("give another file a filename: ");
scanf("%s",filename1);
ch=getchar();
sprintf(filepath1,"/socketTest/photo/%s",filename1);
if((fp1=fopen(filepath1,"w+"))==NULL)
{
printf("cannot open the file <%s>\n",filename1);
return 0;
}//if
printf("the length of %s is %d\n",filename1,strlen(filepath1));
if((fp=fopen(filepath,"r"))==NULL)
{
printf("cannot open the file <%s>\n",filename);
return 0;
}//if
while(fgetc(fp)!=EOF)
{
printf("%c",fgetc(fp));
fputc(fgetc(fp),fp1);
}
fclose(fp1);
fclose(fp);
printf("\n file %s is ok!\n",filename1);
}//main