哦!谢谢指点!
源程序:
#include<stdio.h>
#include<dir.h>
int main()
{
FILE *p,*fp;
char path_in[30]="*.txt",ttt[30]="worktyle\\ttt.txt",bofile[100],buff[100];
int i=0,done=1;
struct ffblk ffblk;
done = findfirst("*.txt",&ffblk,0);
if(done)
{ printf("can't find source file in \n");exit(1);
}//end if
if((fp=fopen(ffblk.ff_name,"r"))==NULL)
{ fclose(fp);printf("can't open source file\n");exit(1);
}//end if
fread(buff,sizeof(char),5,fp);
if((p=fopen(ttt,"w"))==NULL)
{ printf("p is %p\n",p);
printf("can't create a worktyle\\ttt.txt file\n");fclose(p);getch();exit(1);
}//end if
sprintf(bofile,"%s%s%s","\\",buff,".txt");
for(i=0;i<100;i++)
{
fprintf(p,"%c\\%dEND\n",bofile[i],bofile[i]);
} //end for
fprintf(p,"bofile:%sEND\n",bofile);
fclose(fp);fclose(p);
printf("in worktyle\\ttt.txt file \n");
getch();
return 0;
}// end main
问题:
{如下
为何使用%c格式fprintf(p,"%c\\%dEND\n",bofile[i],bofile[i]);
与使用%s格式会出现不同结果fprintf(p,"bofile:%sEND\n",bofile);
萛-56END
鏫-25END
篭-70END
蝄-50END
籠-69END
bofile:\如何?txtEND
}//
{如下
fprintf(p,"%c\\%dEND\n",bofile[i],bofile[i]);
使用%s的时候‘ . ’怎么不见了。却变成了?号fprintf(p,"bofile:%sEND\n",bofile);
.\46END
t\116END
x\120END
t\116END
bofile:\如何?txtEND
}//