ASCII转换成二进制的数据类型代码出错,请求各位大神帮忙

yhj0818 2014-10-17 04:03:49
我是把ASCII类型的数据转换成二进制类型的数据:
#include <stdlib.h>
#include <stdio.h>
int transform(char *szFlag)
{
FILE *fpIn=NULL,*fpOut=NULL;
//int iYearStart=2012;
//int iYearEnd=2012;
int iLine=471,iCol=669;
int iY,iD,iH,i,j;
char szInPath[256],szOutPath[256];
float fValue;
int iValue;
char szInFilename[256],szOutFilename[256];

sprintf(szInPath,"E:\\data\\awc\\awc.txt");
sprintf(szOutPath,"E:\\data\\awc_p\\");


//for(iY=iYearStart;iY<=iYearEnd;iY++)
//{

//printf("\nYear=%d",iY);
iY=1;iD=1;
//for(iD=1;iD<=1;iD++)
//{
printf("\nDay=%d.%d",iY,iD);

//for(iH=0;iH<24;iH++)
//{

sprintf(szInFilename,"%s",szInPath);
sprintf(szOutFilename,"%s%d.img",szOutPath,iD);
//printf("\ninput %s",szInFilename);
//printf("\noutput %s",szOutFilename);
fpIn=fopen(szInFilename,"r");
if(fpIn==NULL)
{
printf("\nOpen input %s failed!",szInFilename);
//continue;
}
fpOut=fopen(szOutFilename,"wb");
if(fpOut==NULL)
{
printf("\nOpen output %s failed!",szOutFilename);
fclose(fpIn);
//continue;
}
for(i=0;i<iLine;i++)
{
for(j=0;j<iCol;j++)
{
fscanf(fpIn,"%f ",&fValue);
iValue=(int)fValue;
fwrite((char*)&iValue,sizeof(float),1,fpOut);
}
}
fclose(fpIn);
fclose(fpOut);
return 0;
}
//}
//}

//}
int main()
{
printf("\nStart");

transform("awc.txt");

return 0;
}
这个程序刚开始还能运行成功,但自从电脑中病毒后,我在别的电脑上对着个数据进行转换,就会一直出错,若放到E盘则会出现runtime error,R6002 floating point support not loaded,我进行单步调试时,出现szInFilename”烫烫烫烫烫烫”"E:\\data\\awc_p\\";指针fpIn出现问题,应该是因为szInPath
和szInFilename出问题了,但是我的输入路径是正确的啊!

我的ASCII数据的前两行是
239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 174 174 174 174 174 174 174 174 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239
239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 303 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 149 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 174 174 174 174 174 174 174 174 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 237 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239 239

...全文
241 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhj0818 2014-10-18
  • 打赏
  • 举报
回复
谢谢各位,我用卡巴斯基进行杀毒,现在软件可以正常运行了
铖邑 2014-10-17
  • 打赏
  • 举报
回复
重装一下系统吧,要不换台机器试试看
yhj0818 2014-10-17
  • 打赏
  • 举报
回复
弱弱地问一问赵老师,我那个代码有问题吗?如果没有问题,为什么不能运行成功?
yhj0818 2014-10-17
  • 打赏
  • 举报
回复
调试一直不成功,以前可以运行成功,现在不行了
铖邑 2014-10-17
  • 打赏
  • 举报
回复
没问题啊,怎么回事?
赵4老师 2014-10-17
  • 打赏
  • 举报
回复
仅供参考
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
int r;
unsigned int n,c;
long offset;
//-------------------------------------------------------
void main(int argc,char *argv[])
{
    if (argc<3) {
        cprintf("Hex2Bin srcfile desfile");
        return;
    }
    if ((fi=fopen(argv[1],"rb"))==NULL) {
        cprintf("Can not find file %s",argv[1]);
        return;
    }
    if ((fo=fopen(argv[2],"wb"))==NULL) {
        fclose(fi);
        cprintf("Can not create file %s",argv[2]);
        return;
    }
    n=0;
    while (1) {
        offset=ftell(fi);
        r=fscanf(fi,"%2x",&c);
        if (EOF==r) break;//
        if (1==r) {
            fputc(c,fo);
            n++;
        } else {//0==r
            fseek(fi,offset,SEEK_SET);//因为VC6的Release版及其VC7,8,9,10,...版的fscanf未按约定保持offset不变,所以此处必须恢复offset
            r=fgetc(fi);
            if (EOF==r) break;//
        }
    }
    fcloseall();
    cprintf("OK to Hex2Bin %d bytes.",n);
}

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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