免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1248 | 回复: 5
打印 上一主题 下一主题

如何在C程序中去掉报文中^M!(急) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-12-19 19:15 |只看该作者 |倒序浏览
UNIX下,对方传来的报文中^M,如何在C程序中处理掉!急!请高手赐教!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-12-19 19:18 |只看该作者

如何在C程序中去掉报文中^M!(急)

把你的题目编辑了。
起一个有意义的名字。

论坛徽章:
0
3 [报告]
发表于 2004-12-19 19:45 |只看该作者

如何在C程序中去掉报文中^M!(急)

dos2unix <file>;

论坛徽章:
0
4 [报告]
发表于 2004-12-19 19:49 |只看该作者

如何在C程序中去掉报文中^M!(急)

[quote]原帖由 "5840"]dos2unix <file>;[/quote 发表:


我想直接在程序中处理,即从内存中读出来处理掉再写回去,源请各位赐教!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2004-12-19 21:35 |只看该作者

如何在C程序中去掉报文中^M!(急)

查win_hate的一篇帖子,详细讲述了DOS下和UNIX下文本文件的不同。将不同的那个自己改成相同的就可以了。

论坛徽章:
0
6 [报告]
发表于 2004-12-19 23:38 |只看该作者

如何在C程序中去掉报文中^M!(急)

请各位高手看看我的代码错在哪里,或着如何写更合适!
int        YDCL_Recv (int fd, char * buff)
{
        int nbytes, result;
        int templen,reflag;
        char *p;
        char tmp[5];
        FILE        *electfp;
        char fpwjmc[30];
        int len55,iii;
        char *strbuff;
        char *strtmp;
        char *strbuff_tmp;
       
        char dlczy[5];
        char jylx[3];

        strbuff=(char *)malloc(8400);
        strtmp=(char *)malloc(8400);
        strbuff_tmp=(char *)malloc(8400);

REFLAG:
        memset(strbuff_tmp,0,8400);
        memset(tmp,0,5);

        nbytes = 0;//接收长度
        do{
                result = recv (fd, tmp+nbytes, 4-nbytes, 0);
                nbytes += result;
        } while ((nbytes<4)&&(result>;0)&&(nbytes>;0));

        if(result<0)return(-1);

        templen = atoi (tmp);
        reflag=atoi(tmp);
        if (templen == 0) return (0);

        memset(tmp,0,5);

        nbytes = 0;
        do {
                result = recv (fd, strbuff_tmp+nbytes, templen-nbytes, 0);
                nbytes += result;
        } while ((nbytes<templen)&&(result>;0)&&(nbytes>;0));
        if(result<0)return(-1);
        if (nbytes != templen)
        {
                return (-1);
        }
        /***************以下 处理
Begin***************/
        strcat(strbuff,buff);
        if (reflag==0) goto REFLAG;
        free(strbuff_tmp);

        strncpy(jylx,strbuff_tmp+2,2);

        if(strcmp(jylx,"11",)==0)
        {
        strncpy(dlczy,strbuff+7,4);
        sprintf(fpwjmc,"log/elect%s.prn",dlczy);
        electfp=fopen(fpwjmc,"w";
        if (electfp==NULL) return(1001);

        len55=strlen(strbuff);
        for (iii=0;iii<len55;iii++)
        {
                if (strbuff[iii]!=0x0a&&strbuff[iii]!=0x0d) fprintf(electfp,"%c",strbuff[iii]);
                if (strbuff[iii]==0x0a) fprintf(electfp,"\n";
        }
        memset(tmp,0,5);
        fseek(electfp,SEEK_SET,0);
        fread(tmp,len55+1,1electfp);
        strcat(buff,tmp);
        fclose(electfp);
                memset(tmp,0,5);
        }
        else
         strcat(buff,strbuff_tmp);
        /***************处理
完成END**************/
        nbytes=strlen(buff);
        return (nbytes);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP