日期:2014-05-16  浏览次数:20773 次

linux下用fopen和fread,fwrite来读写一个文件,为什么里面的数据会变????
打开读文件:yuyv_fp = fopen(yuyv_file_name, "rb");     
打开写文件:yuv420_fp = fopen(yuv420_file_name, "wb"); 

uint8_t yuv_frame[640*480*2];

读:fread (yuv_frame,1,to_read_bytes, yuyv_fp);
写:fwrite(yuv_frame,1,640*480*2, yuv420_fp);
循环一定次数后读写完

我只是简单的读取源文件的内容然后将其写到目标文件内
这里源文件和目标文件按理说应该是一样的
可是用cmp -l  或是  cmp -s 命令得到的结果都是说两者不相同
想请问下大家看下小弟程序是哪里不妥   多谢多谢!!

------解决方案--------------------
你每次都读到同一个地方yuv_frame么?
readed_bytes =  fread (yuv_frame,1,to_read_bytes, yuyv_fp);

因该readed_bytes = fread (yuv_frame +total_read_bytes  ,1,to_read_bytes, yuyv_fp);


引用:
引用:readed_bytes =  fread (yuv_frame,1,to_read_bytes, yuyv_fp);
rest_bytes -=to_read_bytes;
total_read_bytes +=to_read_bytes;

这里红色的两个to_read_bytes要改成readed_bytes,因为最后一次r……