BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #48951同步于 2011/1/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

请大家帮忙看看这个小程序

FLYMAN
2011/1/19镜像同步2 回复
实现一个很简单的功能,从一个文本文件中读入1000个字符,然后以二进制的形式输出到另一个文件。现在输出的结果貌似还是字符型。。 #include <stdio.h> #include <stdlib.h> void main() { char Input[1000]; char tmp; int suc = 1; int size = sizeof(Input); FILE * InputFile, *OutputFileBinary; // InputFile if( (InputFile = fopen("D:\\data.txt", "r")) == NULL ) { printf("Can not open file!\n"); exit(0); } // OutBinaryFile if( (OutputFileBinary = fopen("D:\\data.tdmp", "wb+")) == NULL ) { printf("Binary File Never Exist!\n"); exit(0); } suc = fread(Input,sizeof(char),size,InputFile); if(suc<0) { printf("Error in the read data!\n"); } for(int i=0;i<size;i++) { tmp = Input[i]; fwrite(&tmp, 1, 1, OutputFileBinary); } fclose(InputFile); fclose(OutputFileBinary); }
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
a206206机器人#1 · 2011/1/19
你没做二进制转换怎么就输出了。。。
FLYMAN机器人#2 · 2011/1/19
【 在 a206206 的大作中提到: 】 : 你没做二进制转换怎么就输出了。。。 : -- 以二进制的方式打开一个文件不可以?