[問題] cat:no such file or directory

看板C_and_CPP作者 (佛羅倫斯)時間8年前 (2015/11/10 20:52), 8年前編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
我要在code中執行cat ooo.html 所以我在code中寫execlp("/bin/cat","cat","ooo.html",NULL) 執行完有跑出正確的結果 但是我如果用pch1=strtok(readcmd," ");pch2=strtok(NULL," "); readcmd="cat ooo.html"(readcmd是從鍵盤輸入) 我把pch2印出來也是ooo.html 然後我再寫execlp("/bin/cat","cat",pch2,NULL) 執行的結果就會變成如下錯誤訊息 cat: ooo.html no such file or directory 我用strcmp(pch2,"ooo.html")回傳的結果是>0不是等於0 表示pch2不是"ooo.html" 這樣是不是表示strtok加一些字元到pch2? 我要對pch2做甚麼處理 才能使用execlp("/bin/cat","cat",pch2,NULL) 而不會出現錯誤訊息? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.115.53.27 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1447159958.A.7CA.html ※ 編輯: florenceL (140.115.53.27), 11/10/2015 20:56:00 ※ 編輯: florenceL (140.115.53.27), 11/10/2015 20:58:31 ※ 編輯: florenceL (140.115.53.27), 11/10/2015 21:04:01

11/10 21:52, , 1F
找到原因了是strtok會多塞空字元
11/10 21:52, 1F
文章代碼(AID): #1MGUYMVA (C_and_CPP)