[問題] 請問一下strchr的問題

看板C_and_CPP (C/C++)作者 (阿吉)時間16年前 (2009/08/12 11:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我昨天提出的問題 我把問題縮小一點 void strchrn(char* dest,char* dest2,const char* src) { cout << strlen(src)<<endl; char *n = strchr(src,',') ; cout << "n=" << n+1 <<endl; char *p = strchr(src,'=');; n = strchr(src,'='); cout << "n1=" << n << endl; cout << "n2=" << n << endl; printf ("n=%s\n", n); printf ("%s\n", p); } 這是程式片段 輸入一個string N1,N2,N3,N6,N7; 然而 n1 n2 應該為NULL但是確無法輸出正確的結果 而printf 則可以正確輸出 NULL 這是為什麼呢 謝謝大家了 ============================程式結果=============== 15 n=N2,N3,N6,N7; n1=n=(null) (null) =================================================== -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 134.208.2.154
文章代碼(AID): #1AWZFsN5 (C_and_CPP)
文章代碼(AID): #1AWZFsN5 (C_and_CPP)