⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_39802.htm

📁 vc
💻 HTM
字号:
<p>
序号:39802 发表者:Chuicy 发表日期:2003-05-13 20:57:05
<br>主题:fread and fwrite
<br>内容:It should be very simple, but I really can't find the problem.so for help:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;FILE *fp1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;FILE *fp2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fp1=fopen("text_transmit.txt","rb");<BR>&nbsp;&nbsp;&nbsp;&nbsp;fp2=fopen("text_receive.txt","wb");<BR>&nbsp;&nbsp;&nbsp;&nbsp;int i=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while((getc(fp1))!=EOF)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int nr_size_short=i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;char *a=new char[nr_size_short];<BR>&nbsp;&nbsp;&nbsp;&nbsp;fread(a,sizeof(char),nr_size_short,fp1); <BR><BR>&nbsp;&nbsp; //when comes to this,the value is a is totally wrong, just -51 'f',?//<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;fclose(fp1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fwrite(a,sizeof(char),nr_size_short,fp2);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fclose(fp2);<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:dr0 回复日期:2003-05-13 21:27:50
<br>内容:fread(a,sizeof(char),nr_size_short,fp1);  <BR>// when your codes comes here, the FILE pointer is now pointing to the<BR>// nr_size_short + 1, so when you call the fread() , it will read from<BR>// the nr_size_short + 1. you can reset the FILE pointer to the begining<BR>// use fseek(fp1, 0, 0). have a try ? 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -