关于字符数组做为字符串传递的问题(高分解答,给第一位解答正确的人)
bool read_line(FILE *fp,char *mstr)
{
int j = 0;
while(true)
{
mstr[j] = fgetc(fp);
if(mstr[j] == EOF)
{
mstr[j] = 0;
return false;
}
j++;
if(mstr[j-1]==0x0D)
{
mstr[j] = fgetc(fp);
if(mstr[j] == EOF)
{
mstr[j-1] = 0;
return false;
}
if(mstr[j] == 0x0A)
{
mstr[j-1] = 0;
break;
}
else
{
fseek(fp,-1,SEEK_CUR);
}
}
}
return true;
}
void new_list()
{
FILE* fp, *ou;
char bbbbuf[MAX_PATH];
char head[MAX_PATH];
strcpy(head,"wPack.exe");
self_dir(head);
fp = fopen(dir_list_tmp_file,"rb");
assert(fp!=NULL);
ou = fopen(new_list_file_name,"wb");
assert(ou!=NULL);
while(read_line(fp,bbbbuf))
{
cut_head(bbbbuf,head);
fprintf(ou,"%s\n",bbbbuf);
}
fclose(ou);
fclose(fp);
}
void main()
{
new_list();
}
此过程为什么为出错,VC++6.0编译时是无法查出错误,在运行期间会出现没有分配的空间引用错误。
源数据文件内容为:
任意找一目录,用 dir /b /s /on >out.txt
out.txt 就是所用的数据文件