看板 C_and_CPP 關於我們 聯絡資訊
我想請問一下memset的問題 假設我有類似下面這段code 理論上應該都不會print出東西 可是實際上確卻 請問是我哪邊弄錯了嗎? 謝謝 void test(struct contract *temp) { memset(temp->testno, NULL, sizeof(temp->testno)); //char testno[3][80] } void main() { struct contract temp; test(&temp); for(int i = 0; i < 3; i++) if(strcmp(temp.testno[i], NULL)) printf("testno != NULL"); } -- ╔╮ ╭═╦╮╭═╦╗╮ ╮╔══╮╭═╦╮╮ ╔╮╔══╮╭══╮ ╠╣ ╠═╬╣╭╬╩╯╰╦╦╯╠═╦╮║ ╠╣║║╠╣╠╣ ╰═╦╮ ╠╣ ╭║ ╠╣║╰╔╗ ╠╣ ║ ╠╣║ ╠╣║╰╠╣║╰╔╗║ ╠╣ ╰╩═╯╰ ╰╝╚═╩╯ ╰╝ ╚═╩╯╰═╩╯╰ ╰╝╚═╩╯╰═╩╯ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.211.0.80
ckclark:testno[i]不是pointer 是array 不會為null 04/19 15:45
VictorTom:strcmp() 裡的 NULL 換成 "" 試試呢:) 04/19 15:45
lazybones:感謝樓上2位!可以了!! 04/19 16:09