njuhuangmy兄谢谢你帮我解决问题,奉上另外的90分,

poemlake 2003-12-08 05:41:24
我发了这个贴,你回复就给你加分啊,呵呵
我遇到一个难题,我是学pb的,对于C语言一点也不懂,我往27c512 的eprom中写文件(文件最大512K),这个文件为扩展名为bin的,是由几个扩展名为.e80的二进制文件合并在一起的,反过来,用eprom读写器读出来以后,为一个整体的二进制文件为.bin 现在要做两个程序,一个是把几个文件(001.e80,002.e80 003.e80 ......)合并在一起,存成.bin文件,一个是把这个 bin文件再分成几个文件,分别存成单个e80文件(001.e80,002.e80,003.e80..... )我注意过,每个e80的文件结尾是 80 80
但数据中间也有 80 80 但可以判断每个e80文件的结尾是80 80 ff ,不能增加e80文件的长度,
我把单个的e80文件和bin文件上传一个打包文件
http://go.6to23.com/poemlake/e80.rar
有哪位热心的朋友帮写一段代码,我在pb中做了一半,但速度太慢,所以想用C,有哪位朋友提供帮助的,我给500分,分不够,我另加,QQ:70237855
...全文
29 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
njuhuangmy 2003-12-09
  • 打赏
  • 举报
回复
我认为这一个可能对你的程序比较管用,先try这个吧!
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

unsigned char mark[16];
unsigned char mark2[10];

unsigned int notend(unsigned char* rbuf)
{
int i;
// i 0 ---- 7

mark2[0] = 0x80;
mark2[1] = 0x80;

memset(mark2 + 2, 0xff, 8);

for (i = 0; i < 7; i++)
{
if (memcmp(rbuf++, mark2, 10) == 0)
return i + 10;
}

return 16;
}

void combine(int n, char **fn)
{
int i, rnum;

unsigned char wbuf[16];

FILE* out = fopen(fn[n + 1], "wb+");

for (i = 1; i <= n; i++)
{
FILE* in = fopen(fn[i], "rb+");

while (!feof(in))
{
memset(wbuf, 0xff, 16);
rnum = fread(wbuf, 1, 16, in);

if (rnum != 0)
fwrite(wbuf, 1, 16, out);
}

fclose(in);
fwrite(mark, 1, 16, out);
}

fclose(out);
}

void separate(char *fn)
{
int i = 0, rnum, wnum;

// less than 10 files, filename is less than 30 characters
char e80[10][30] = {"001.e80", "002.e80",
"003.e80", "004.e80",
"005.e80", "006.e80",
"007.e80", "008.e80",
"009.e80", "010.e80"};

unsigned char rbuf[16];

FILE* in = fopen(fn, "rb+");

while ( (i < 10) && (!feof(in)) )
{
FILE* out;

rnum = fread(rbuf, 1, 16, in);
while (memcmp(rbuf, mark, 16) == 0)
rnum = fread(rbuf, 1, 16, in);

if (rnum > 0)
out = fopen(e80[i++], "wb+");

while (!feof(in))
{
if (memcmp(rbuf, mark, 16) != 0)
{
wnum = notend(rbuf);
fwrite(rbuf, 1, wnum, out);
fread(rbuf, 1, 16, in);
}
else
break;
}
fclose(out);
}

fclose(in);
}


int main(int argc, char* argv[])
{
memset(mark, 0xff, 16);

if (argc == 1)
{
printf("Usage: cmd filename[filename......]\n");
return 1;
}
else if (argc == 2)
{
puts("separate .e80 from .bin\n");
separate(argv[1]);
return 0;
}
else
{
puts("combine .e80 to .bin\n");
combine(argc - 2, argv);
return 0;
}
}
njuhuangmy 2003-12-09
  • 打赏
  • 举报
回复
我一共做两种修改,你看看那一种对你的程序比较适用

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

unsigned char mark[16];
unsigned char mark2[10];

unsigned int notend(unsigned char* rbuf)
{
int i;
// i 0 ---- 7

mark2[0] = 0x80;
mark2[1] = 0x80;

memset(mark2 + 2, 0xff, 8);

for (i = 0; i < 7; i++)
{
if (memcmp(rbuf++, mark2, 10) == 0)
return i + 10;
}

return 16;
}

void combine(int n, char **fn)
{
int i, rnum;

unsigned char wbuf[16];

FILE* out = fopen(fn[n + 1], "wb+");

for (i = 1; i <= n; i++)
{
FILE* in = fopen(fn[i], "rb+");

while (!feof(in))
{
memset(wbuf, 0xff, 16);
rnum = fread(wbuf, 1, 16, in);

if (rnum != 0)
fwrite(wbuf, 1, 16, out);
}

fclose(in);
fwrite(mark, 1, 16, out);
}

fclose(out);
}

void separate(char *fn)
{
int i = 0, rnum, wnum;

// less than 10 files, filename is less than 30 characters
char e80[10][30] = {"001.e80", "002.e80",
"003.e80", "004.e80",
"005.e80", "006.e80",
"007.e80", "008.e80",
"009.e80", "010.e80"};

unsigned char rbuf[16];

FILE* in = fopen(fn, "rb+");

while ( (i < 10) && (!feof(in)) )
{
FILE* out;

rnum = fread(rbuf, 1, 16, in);
if ((rnum > 0) && (memcmp(rbuf, mark, 16) != 0))
/*上面这一行被修改了*/
out = fopen(e80[i++], "wb+");

while (!feof(in))
{
if (memcmp(rbuf, mark, 16) != 0)
{
wnum = notend(rbuf);
fwrite(rbuf, 1, wnum, out);
fread(rbuf, 1, 16, in);
}
else
break;
}
fclose(out);
}

fclose(in);
}


int main(int argc, char* argv[])
{
memset(mark, 0xff, 16);

if (argc == 1)
{
printf("Usage: cmd filename[filename......]\n");
return 1;
}
else if (argc == 2)
{
puts("separate .e80 from .bin\n");
separate(argv[1]);
return 0;
}
else
{
puts("combine .e80 to .bin\n");
combine(argc - 2, argv);
return 0;
}
}
poemlake 2003-12-08
  • 打赏
  • 举报
回复
我现在结贴了,你要帮我改一下然后直接回贴就行了,谢谢了。我真的一点不懂C语言。
poemlake 2003-12-08
  • 打赏
  • 举报
回复
明天你帮我改好啊,我对C一点也不懂啊,谢谢了,我有事先出去了,明天晚上能回来。
njuhuangmy 2003-12-08
  • 打赏
  • 举报
回复
没多生成文件阿

阿,我知道了,你的那个是因为 .bin 后面多了许多许多 0xff

明天改好了再发给你:)

下面的还没有改, 你自己也可以改的

就在 separate 里面 ,两个 while 之间控制一下

我是放在之间的,可能 放在 第二个 while 里面会比较好

现在的条件判定的 还不是 很好

测试这个程序,有一个法子就是,你先 combine ,用combine的再去 separate

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

unsigned char mark[16];
unsigned char mark2[10];

unsigned int notend(unsigned char* rbuf)
{
int i;
// i 0 ---- 7

mark2[0] = 0x80;
mark2[1] = 0x80;

memset(mark2 + 2, 0xff, 8);

for (i = 0; i < 7; i++)
{
if (memcmp(rbuf++, mark2, 10) == 0)
return i + 10;
}

return 16;
}

void combine(int n, char **fn)
{
int i, rnum;

unsigned char wbuf[16];

FILE* out = fopen(fn[n + 1], "wb+");

for (i = 1; i <= n; i++)
{
FILE* in = fopen(fn[i], "rb+");

while (!feof(in))
{
memset(wbuf, 0xff, 16);
rnum = fread(wbuf, 1, 16, in);

if (rnum != 0)
fwrite(wbuf, 1, 16, out);
}

fclose(in);
fwrite(mark, 1, 16, out);
}

fclose(out);
}

void separate(char *fn)
{
int i = 0, rnum, wnum;

// less than 10 files, filename is less than 30 characters
char e80[10][30] = {"001.e80", "002.e80",
"003.e80", "004.e80",
"005.e80", "006.e80",
"007.e80", "008.e80",
"009.e80", "010.e80"};

unsigned char rbuf[16];

FILE* in = fopen(fn, "rb+");

while ( (i < 10) && (!feof(in)) )
{
FILE* out;

rnum = fread(rbuf, 1, 16, in);
if (rnum > 0)
out = fopen(e80[i++], "wb+");

while (!feof(in))
{
if (memcmp(rbuf, mark, 16) != 0)
{
wnum = notend(rbuf);
fwrite(rbuf, 1, wnum, out);
fread(rbuf, 1, 16, in);
}
else
break;
}
fclose(out);
}

fclose(in);
}


int main(int argc, char* argv[])
{
memset(mark, 0xff, 16);

if (argc == 1)
{
printf("Usage: cmd filename[filename......]\n");
return 1;
}
else if (argc == 2)
{
puts("separate .e80 from .bin\n");
separate(argv[1]);
return 0;
}
else
{
puts("combine .e80 to .bin\n");
combine(argc - 2, argv);
return 0;
}
}
poemlake 2003-12-08
  • 打赏
  • 举报
回复
楼上的大哥,你分的倒是对,但分割后出现几个空的文件,这个没法解决吗?
绿源化工二甲醚生产线设计项目是一项旨在探究和实现二甲醚生产的创新工程,其核心在于构建一个既经济又环保的生产工艺。通过深入市场调研、技术析和财务评估,本可行性研究报告详尽地阐述了项目的必要性、实施步骤以及预期的经济、社会和环境效益。报告指出,随着能源需求的增长和环保标准的提升,二甲醚作为一种清洁燃料和重要的化工原料,其市场需求正逐渐扩大。因此,建设一条高效、低排放的二甲醚生产线不仅能满足市场的需要,还能促进相关产业的升级。在技术层面,报告提出了采用先进的合成气技术和催化剂,以提高转化率和产品纯度,同时降低生产成本。此外,项目还着重考虑了生产过程中的能源回收与循环利用,力求达到节能减排的目的。经济析部显示,通过合理的财务规划和成本控制,该项目有望在投产后几年内实现盈利,并为投资者带来稳定的回报。从社会效益角度出发,绿源化工的二甲醚生产线能够为当地创造就业机会,推动地方经济发展,并有助于缓解环境污染问题。报告还强调了项目在执行过程中将严格遵守环保法规,确保生产过程安全且对环境的影响最小化。综上所述,绿源化工二甲醚生产线设计项目是一个集技术创新、经济效益和社会责任于一体的创业计划。它不仅

69,324

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧