C 如果条件不满足';行不通

C 如果条件不满足';行不通,c,if-statement,C,If Statement,我有这部分代码: void query(hash_t* params) { record_t* rec; // Coordinator, opgroup and Opcode specified by the client uint64_t netid = 0; uint8_t op_code_group = 0; uint8_t op_code = 0; char* par; now = mdl_now(); /* set the start and end time based on

我有这部分代码:

void query(hash_t* params) {
record_t* rec;

// Coordinator, opgroup and  Opcode  specified by the client
uint64_t netid = 0;
uint8_t op_code_group = 0;
uint8_t op_code = 0;
char* par;
now = mdl_now();
/* set the start and end time based on query parameters */
...........
// Network id is required
par = hash_get(params, "netid");
...........
netid = strtoull(par, NULL, 10);
par = hash_get(params, "opcode_group");
...........
op_code_group = strtoul(par, NULL, 10);
par = hash_get(params, "opcode");
...........
op_code = strtoul(par, NULL, 10);
/* seek in the bytestream */
mdl_seek(start);
while((rec = (record_t* ) mdl_next(&ts)) != NULL) {
    ...............
    // Only print records with the wanted net and opcodes
    if((netid != 0) && (netid != NTOHLL(rec->net_id))) 
        continue;
    if((opcode_group != 0) && (op_code_group != ntohl(rec->opcode_group))) 
        continue;
    if((opcode != 0) && (op_code != ntohl(rec->opcode)))
        continue;
    ..............
    mdl_print("%u %llu %u %u %u %d\n", 
        sec, 
        NTOHLL(rec->net_id), 
        rec->op_code_group, 
        rec->op_code, 
        rec->payloadlength, 
        val);
     }
 }
opcode_组、opcode和其他参数通过http请求传递给查询类

问题是: 如果我指定一个操作码组,例如=160,结果不会显示任何内容。相反,如果我指定操作码组=0(所有记录),结果将显示所有记录,包括操作码组=160的记录


错误在哪里?非常感谢。

我可以查看代码,发现只获取变量“操作码组”中的值,而不是“操作码组”

我相信你在处理类似的变量

\u编辑

我相信问题在于这部分

if((opcode_group != 0) && (op_code_group != ntohl(rec->opcode_group))) 
    continue;"   
此部件将失败,仅当操作码_group==0时才打印记录

将此修改为

if((opcode_group == 0) || (op_code_group != ntohl(rec->opcode_group))) 
    continue;"  

我猜你也面临同样的问题,netid和op_代码

现在是开始学习如何使用调试器的好时机。调试器非常擅长帮助你发现bug。用它!你能告诉我CentOS的调试器吗?我不知道怎么做…是的-gdb是显而易见的选择-有很多gdb教程。或者,您可以在代码中添加一些printf来帮助您了解发生了什么。。。可能已经安装了,如果没有的话,在以前的版本中肯定有一个centos软件包。变量和参数都是操作码组和操作码。接下来,我认为问题是同一个名称,所以我更改了op_code_组和op_code中的局部变量。但是问题没有解决。@sharkbait请查找编辑的答案不起作用。你的解决方案不再显示任何内容。另外,当我使用这个http请求调用该类时,无论如何,它应该显示流中的每个记录,操作码组不是一个局部变量。我不能用。我只能使用op_代码组。但它不起作用。你也需要用同样的方法改变netid和操作码的条件
if((opcode_group == 0) || (op_code_group != ntohl(rec->opcode_group))) 
    continue;"