2013-03-06 69 views
0

我有這部分代碼:如果條件不工作

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_group,操作碼和其它參數傳遞到通過http請求的查詢類。

這是一個問題: 如果我指定一個opcode_group例如= 160,結果不會顯示任何東西。相反,如果我指定opcode_group = 0(所有記錄),結果會顯示所有記錄,包括opcode_group = 160的記錄。

錯誤在哪裏?非常感謝你。

+0

現在將開始學習如何使用調試器的好時機。 – 2013-03-06 12:23:25

+0

調試器非常善於幫助您查找錯誤。用它! – 2013-03-06 12:23:30

+0

你可以說我是CentOS的調試器嗎?我不知道該怎麼做... – sharkbait 2013-03-06 12:24:25

回答

1

我可以看到代碼,發現只有在變量所獲得的價值 「op_code_group」,而不是 「opcode_group

op_code_group = strtoul(par, NULL, 10); 

我相信烏爾搞亂類似的變量

_EDITED_ _ __ _ __

我相信問題是這部分

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

這部分將失敗並打印僅當opcode_group == 0

修改這

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

猜猜烏爾面臨的紀錄與netid和op_code相同的probs

+0

在以前的版本中,變量和參數都是opcode_group和opcode。接下來我想這個問題是同名的,所以我改變了op_code_group和op_code中的局部變量。但問題並沒有解決。 – sharkbait 2013-03-06 12:34:55

+0

@sharkbait請找到編輯答案 – hazzelnuttie 2013-03-06 12:48:42

+0

不起作用。你的解決方案不再顯示任何東西。此外,當我用這個http請求調用類http://131.114.52.207:44444/ztc_config?netid=0&opcode_group=0&opcode=0&start=-20s&end=-1s,應該顯示流中的每個記錄 – sharkbait 2013-03-06 12:59:08