[問題] memset的使用

看板C_and_CPP作者 (懶)時間15年前 (2010/04/19 15:42), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
我想請問一下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

04/19 15:45, , 1F
testno[i]不是pointer 是array 不會為null
04/19 15:45, 1F

04/19 15:45, , 2F
strcmp() 裡的 NULL 換成 "" 試試呢:)
04/19 15:45, 2F

04/19 16:09, , 3F
感謝樓上2位!可以了!!
04/19 16:09, 3F
文章代碼(AID): #1Bp0bptI (C_and_CPP)