可恶的百度,追问半天了内容还在审核中。第一个程序输入什么都没关系的,就是第二个程序只要有这一行free(s)就会在程序结束时弹出一个全是英文的窗口说是出错了,没有free(s)就没事#defineBUFFER_SIZE10intmain(void){FILE*pInFile=NULL;FILE*pOutFile=NULL;char*infilename=\"D:\\\\我的文档\\\\c.txt\";char*outfilename=\"D:\\\\我的文档\\\\d.txt\";size_tbuffer_size=BUFFER_SIZE;size_tstr_length=0;intstr_count=0;fpos_t*positions=NULL;inti=0;char*buffer=(char*)malloc(buffer_size);if(!(pInFile=fopen(infilename,\"r\"))){printf(\"Erroropening%sforreading.Programterminated.\",infilename);exit(1);}for(;;){fread(if(feof(pInFile))break;if(str_lengthbuffer_size){buffer_size=str_length1;free(buffer);buffer=(char*)malloc(buffer_size);}fread(buffer,str_length,1,pInFile);str_count;}printf(\"\\nThereare%dstringsintheinputfile.\",str_count);rewind(pInFile);positions=(fpos_t*)malloc(str_count*sizeof(fpos_t));for(i=0;istr_count;i){fgetpos(pInFile,positionsi);fread(fread(buffer,str_length,1,pInFile);}if(!(pOutFile=fopen(outfilename,\"w\"))){printf(\"Erroropening%sforreading.Programterminated.\",outfilename);exit(1);}for(i=0;istr_count;i){fsetpos(pInFile,positionsstr_count-i-1);fread(fwrite(fread(buffer,str_length,1,pInFile);fwrite(buffer,str_length,1,pOutFile);}fclose(pInFile);fclose(pOutFile);printf(\"\\nNewfilewritecomplete.\\n\");pOutFile=fopen(outfilename,\"r\");printf(\"\\nThestringsinthenewfileare:\");for(i=0;istr_count;i){fread(fread(buffer,str_length,1,pOutFile);buffer[str_length]=\'\\0\';printf(\"\\n%s\",buffer);}printf(\"\\n\");fclose(pOutFile);free(buffer);free(positions);return0;}这是书里的代码,它的是对的,我完全照着编的,不明白为什么就出错
|