我的struct的两个值不能打印正确的值

时间:2014-04-25 01:16:28

标签: pointers printing struct

我定义了以下结构:

typedef struct word {
    const char *str;
    int freq;
    int edit_list;
} Word;

在我的main函数中,我使用预定义的向量来存储Word类型的集合(如上面的结构中所定义)。名为corrections的Vector已经定义,并且还拥有它自己的迭代器。

for(const Word *key = cvec_first(corrections); key != NULL; key = cvec_next(corrections, key)) {
    print("%s\n", key->str);
    print("%d\n", key->freq);
    print("%d\n", key->edit_dist);
}

for循环遍历单词集合,我打算打印出Word结构的每个值。但是,只有str类型才能正确打印出来,而freqedit_dist会打印出垃圾值。

0 个答案:

没有答案