24小时热门版块排行榜    

Znn3bq.jpeg
查看: 835  |  回复: 1

13659938271

铁虫 (初入文坛)

[求助] 这个是gdb调试错误代表什么意思 已有1人参与

Program received signal SIGSEGV, Segmentation fault.
0x00684867 in __strcmp_sse4_2 () from /lib/libc.so.6
上面这句是什么意思


程序如下:
再没有调用add_specie的时候可以运行,但是一旦调用就出现了段错误


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LINE 500                  
#define MAX_REACTIONS 6046
#define MAX_SPECIES 5000            
#define MAX_CHAR_SPECIES 32  




     







void add_specie (char *new_specie, char *species[],int *n_species)
{
        int i;

     
        if (strcmp (new_specie, "") == 0)
                return;
        for (i = 0; i < *n_species; i++)
        {
                if (strcmp (species, new_specie) == 0)
                        return;
        }
        i = *n_species;
        if (i < MAX_SPECIES )
        {
                if (strlen (new_specie) < MAX_CHAR_SPECIES - 1)
                {
                        strcpy (species, new_specie);
                        (*n_species)++;
                }
               
                       
       
        }

  
        return;
}



int main()
{   
//struct react reactions[MAX_REACTIONS];
const char *osu2009;
FILE *f;                 
char line[MAX_LINE];
int line_number=0;
char reactant1[MAX_CHAR_SPECIES];
char reactant2[MAX_CHAR_SPECIES];
char reactant3[MAX_CHAR_SPECIES];
char product1[MAX_CHAR_SPECIES];
char product2[MAX_CHAR_SPECIES];
char product3[MAX_CHAR_SPECIES];
char product4[MAX_CHAR_SPECIES];
double alpha;
double beta;
double gamma;
int reaction_type;
int reaction_no;
char *species[MAX_SPECIES];
int *n_species;

if((f=fopen("osu2009.chm","r"))==NULL)
{
printf("can not open\n");
exit(0);
}

while(fgets(line,MAX_LINE,f)!=NULL)
{
line_number++;

if (line[0]=='#') continue;

                strcpy (reactant1, "");
                strcpy (reactant2, "");
                strcpy (reactant3, "");
                strcpy (product1, "");
                strcpy (product2, "");
                strcpy (product3, "");
                strcpy (product4, "");
                alpha = 0;
                beta = 0;
                gamma = 0;
                reaction_type = 0;    //付初始值
                reaction_no = 0;


     
if ((sscanf (line, "%s -> %s %lf %lf %lf %d %d",reactant1, product1, &alpha, &beta, &gamma, &reaction_type, &reaction_no) == 7)
           
               ||(sscanf (line, "%s + %s -> %s + %s %lf %lf %lf %d %d",reactant1, reactant2, product1, product2,&alpha, &beta, &gamma, &reaction_type, &reaction_no) == 9)

               ||(sscanf (line, "%s + %s -> %s %lf %lf %lf %d %d",reactant1, reactant2, product1, &alpha, &beta, &gamma, &reaction_type, &reaction_no) == 8)

               ||(sscanf (line, "%s + %s -> %s + %s + %s %lf %lf %lf %d %d",reactant1, reactant2, product1, product2, product3,&alpha, &beta, &gamma, &reaction_type, &reaction_no) == 10)
  
                     || (sscanf (line, "%s + %s -> %s + %s + %s + %s %lf %lf %lf %d %d",reactant1, reactant2, product1, product2, product3,product4,&alpha, &beta, &gamma, &reaction_type, &reaction_no) == 11)
                     ||(sscanf (line, "%s + %s + %s -> %s + %s %lf %lf %lf %d %d",reactant1, reactant2, reactant3, product1, product2,&alpha, &beta, &gamma, &reaction_type, &reaction_no) == 10));



            if ((strcmp (reactant1, "cosmic-ray") == 0)
                        || (strcmp (reactant1, "uv-photon") == 0)
                        || (strcmp (reactant1, "photon") == 0))
                {
                        strcpy (reactant1, reactant2);
                        strcpy (reactant2, reactant3);
                        strcpy (reactant3, "");
                }
                if ((strcmp (reactant2, "cosmic-ray") == 0)
                        || (strcmp (reactant2, "uv-photon") == 0)
                        || (strcmp (reactant2, "photon") == 0))
                {
                        strcpy (reactant2, reactant3);
                        strcpy (reactant3, "");
                }
                if ((strcmp (reactant3, "cosmic-ray") == 0)
                        || (strcmp (reactant3, "uv-photon") == 0)
                        || (strcmp (reactant3, "photon") == 0))
                {
                        strcpy (reactant3, "");
                }
if ((strcmp (product1, "cosmic-ray") == 0)
                        ||(strcmp (product1, "uv-photon") == 0)
                        || (strcmp (product1, "photon") == 0))
                {
                        strcpy (product1, product2);
                        strcpy (product2, product3);
                  strcpy (product3, product4);
                        strcpy (product4, "");
                }
                if ((strcmp (product2, "cosmic-ray") == 0)
                        || (strcmp (product2, "uv-photon") == 0)
                        || (strcmp (product2, "photon") == 0))
                {
                        strcpy (product2, product3);
                  strcpy (product3, product4);
                        strcpy (product4, "");
                }
                if ((strcmp (product3, "cosmic-ray") == 0)
                        || (strcmp (product3, "uv-photon") == 0)
                        || (strcmp (product3, "photon") == 0))
                {
                  strcpy (product3, product4);
                        strcpy (product4, "");
                }
                if ((strcmp (product4, "cosmic-ray") == 0)
                        || (strcmp (product4, "uv-photon") == 0)
                        || (strcmp (product4, "photon") == 0))
                {
                        strcpy (product4, "");
                }


                add_specie (reactant1, species, n_species);
                add_specie (reactant2, species, n_species);
                add_specie (reactant3, species, n_species);
                add_specie (product1, species, n_species);
                add_specie (product2, species, n_species);
                add_specie (product3, species, n_species);
                add_specie (product4, species, n_species);


              //     printf("reactant1:%s  reactant2:%s  reactant3:%s  product1:%s  product2:%s  product3:%s  product4:%s  alpha:%.2e  beta:%.2e  gamma:%e  reaction_type:%d  reaction_no: %d\n",reactant1,reactant2,reactant3,product1,product2,product3,product4,alpha,beta,gamma,reaction_type,reaction_no);



}

               
fclose(f);
return 0;
}
回复此楼

» 猜你喜欢

选择性所得税
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zzy滴号

金虫 (小有名气)

【答案】应助回帖

void add_specie (char *new_specie, char *species[],int *n_species)中的参数species是一个指针数组,而new_specie是一个指针。调用add_specie处传入的参数类型不符,而且二者在 if (strcmp (species, new_specie) == 0)不正确的使用,把[]去掉试一试。
天道酬勤
2楼2015-08-08 08:45:54
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 13659938271 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 评审有感 +3 popular289 2026-05-18 6/300 2026-05-18 15:17 by gy116024
[基金申请] 今年审到国自然15份,谈谈感受 +16 国自然国社科中 2026-05-17 16/800 2026-05-18 14:58 by gy116024
[基金申请] 青C资助名额大幅增加! +12 西葫芦炒鸡蛋 2026-05-13 16/800 2026-05-18 10:02 by Equinoxhua
[硕博家园] 我在等一个没有答案的答案 +3 Love_MH 2026-05-17 3/150 2026-05-18 02:22 by 竹林孤影
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +6 l7k6xnh0yc 2026-05-14 7/350 2026-05-17 19:42 by Equinoxhua
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +6 cjf4bx70cj 2026-05-14 7/350 2026-05-17 18:49 by Equinoxhua
[考博] 找博士生导师 +4 小代想上岸 2026-05-15 5/250 2026-05-17 17:44 by 脱颖而出
[考博] 光量子物理方向 博士招生 1人(2026.09) +3 sandyworld 2026-05-15 4/200 2026-05-17 14:38 by sandyworld
[基金申请] 这年头没有找到涵评专家,还有中面上的可能吗 +13 dd921ww 2026-05-12 16/800 2026-05-17 12:38 by 于轩
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 v9tggjlwd0 2026-05-15 4/200 2026-05-17 08:06 by 11n4dfd8yn
[考博] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 7hlccowb3h 2026-05-15 4/200 2026-05-17 07:46 by 11n4dfd8yn
[考博] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +6 l7k6xnh0yc 2026-05-14 6/300 2026-05-17 07:11 by 11n4dfd8yn
[博后之家] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 k37jurhrau 2026-05-16 4/200 2026-05-17 01:35 by ue3ir18jc3
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 k37jurhrau 2026-05-16 3/150 2026-05-17 01:25 by ue3ir18jc3
[公派出国] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 x0mp7owy2b 2026-05-15 4/200 2026-05-17 00:35 by ue3ir18jc3
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 x0mp7owy2b 2026-05-15 4/200 2026-05-17 00:25 by ue3ir18jc3
[基金申请] 请问大佬b0816评完了吗 +4 市民华南虎 2026-05-12 8/400 2026-05-16 19:54 by Equinoxhua
[高分子] 本人最近太闲了,谁有问题可以提,每天会统一回复 +9 一切都是空工 2026-05-12 20/1000 2026-05-16 19:52 by Equinoxhua
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 l7k6xnh0yc 2026-05-14 6/300 2026-05-16 11:29 by h3oerqvkv9
[硕博家园] 申请博士 +3 呃?呃 2026-05-15 3/150 2026-05-16 11:01 by a4742549
信息提示
请填处理意见