| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 714 人关注过本帖
标题:crc 结果不正确 ,求正确程序!!!!
只看楼主 加入收藏
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:9 
crc 结果不正确 ,求正确程序!!!!
#include <math.h>
#include <stdio.h>
#include<string>
void CRC(char msg[],char gx[])
{
    int i=0,j=0;
    char c[50];
    int m,n;
   
   
        m=strlen(msg);
        n=strlen(gx);

   
    /*将msg的值赋给c*/
    for(i=0;i<m;i++)
    {
        c[i]=msg[i];
    }
   
   
   
   
    for(i=m;i<m+n-1;i++)
    {
        c[i]=0;
    }

   
   
   
   
   
    for(i=0;i<m;i++)
    {
        if(c[i]==0) continue;
        else
        {
            for(j=0;j<n;j++)
            {
                c[i+j]=c[i+j]^gx[j];
            }
        }
    }

   
   
   
    for(i=0;i<n-1;i++)
    {
        msg[m+i]=c[m+i];
    }

   
   
   
   
    printf("The CRC:");    /*输出循环冗余码:数组msg[m+n-1]    */
   
    for(i=0;i<m+n-1;i++)
    {
        printf("%c",msg[i]);
    }
    printf("\n");


   

}







void main()
{   char msg[50];
    char gx[20];
   
   
    printf("\ninput the message's information:\n");        /*输入二进制信息(0 ~ m-1) */
   
        scanf("%s",msg);
 
        printf("input the G(x)'s information:\n");        /*输入二进制生成多项式(0 ~ n-1)*/
   
        scanf("%s",gx);
 
   
     CRC(msg,gx);
            
   
}


[ 本帖最后由 小兔子慢慢 于 2010-4-17 09:41 编辑 ]
搜索更多相关主题的帖子: crc 结果 
2010-04-17 09:00
xiaoxinwan
Rank: 2
等 级:论坛游民
帖 子:52
专家分:91
注 册:2010-4-6
收藏
得分:1 
c[i+j]=c[i+j]^gx[j];由于不知道你这句话要表示什么意思。故后面程序有点看不懂。
但是。单单从C语言规则来说
for(i=0;i<n-1;i++)
    {
        msg[m+i]=c[m+i];
    }

由于msg[m],你已经定义为数量为m的数组了。但是你后面用到了msg[m+i],这个超出了原定于的数组长度。估计是这样出了错误。
你自己在改改。

2010-04-17 10:52
zhanfffmmm
Rank: 5Rank: 5
等 级:职业侠客
帖 子:238
专家分:343
注 册:2009-10-16
收藏
得分:1 
c[i+j]=c[i+j]^gx[j];
,#include<string>不行

2010-04-17 11:32
haojinbing
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2010-4-17
收藏
得分:1 
能讲下你要干嘛 吗?
2010-04-18 17:25
nunununu
Rank: 2
等 级:论坛游民
帖 子:22
专家分:32
注 册:2010-3-31
收藏
得分:1 
完全不明白程序意图
2010-04-18 20:43
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
回复 5楼 nunununu
crc编码
2010-04-19 08:16
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
回复 5楼 nunununu
crc编码
2010-04-19 08:16
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
for(i=0;i<m;i++)
    {
        if(c[i]=='0') continue;
        else
        {
            for(j=0;j<n;j++)
            {
                if(c[i+j]==g[j])
                 c[i+j]='1';
               else
                 c[i+j]='0';
            }
        }
    }
2010-04-19 08:18
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
回复 2楼 xiaoxinwan
crc编码
2010-04-19 08:22
ldg628
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:3
帖 子:526
专家分:3036
注 册:2009-6-23
收藏
得分:6 
void CRC(char msg[],char gx[])
{
    int i=0,j=0;
    char c[50];
    int m,n;

    m=strlen(msg);
    n=strlen(gx);
    /*将msg的值赋给c*/
    for(i=0;i<m;i++)
    {
        c[i]=msg[i];
    }

    for(i=m;i<m+n-1;i++)
    {
        c[i]='0';
    }

    for(i=0;i<m;i++)                                                                                             
    {                                                                                                            
        if(c[i]=='0') continue;                                                                                   
        else                                                                                                      
        {                                                                                                         
            for(j=0;j<n;j++)                                                                                      
            {                                                                                                     
               if(c[i+j]==gx[j])                                                                                 
                 c[i+j]='0';                                                                                      
               else                                                                                               
                 c[i+j]='1';                                                                                      
            }                                                                                                     
        }                                                                                                         
    }                                                                                                            
                                                                                                                  
    for(i=0;i<n-1;i++)                                                                                            
    {                                                                                                            
        msg[m+i]=c[m+i];                                                                                          
    }                                                                                                            
    printf("The CRC:");    /*输出循环冗余码:数组msg[m+n-1]    */                                                  
    for(i=0;i<m+n-1;i++)                                                                                          
    {                                                                                                            
        printf("%c",msg[i]);                                                                                      
    }                                                                                                            
    printf("\n");                                                                                                
}                              

2010-04-19 12:04
快速回复:crc 结果不正确 ,求正确程序!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033687 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved