[問題] 有關strstr()
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev c
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
如程式碼
想請問有甚麼原因會這樣
謝謝
餵入的資料(Input):
strstr("This is a",讀取的資料);
預期的正確結果(Expected Output):
搜尋的到
錯誤結果(Wrong Output):
搜不到
程式碼(Code):(請善用置底文網頁, 記得排版)
FILE *fPtr = fopen("A.txt","r");
char *b;
char txtvalue[10];
fgets(txtvalue, 10, fPtr);
b=strstr("This is a",txtvalue);
if(b!=0)
{
printf("%s",b);
}
fclose(fPtr);
system("PAUSE");
return 0;
A.txt裡面的內容
is
a
b
這樣子的話 找不到
但是只要把 strstr("This is a",txtvalue);的txtvalue寫死成"is"
就找的到..
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 202.5.249.97
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1411842142.A.8B4.html
→
09/28 02:25, , 1F
09/28 02:25, 1F
※ 編輯: momo81 (202.5.249.97), 09/28/2014 02:33:11
→
09/28 02:36, , 2F
09/28 02:36, 2F
有>< 後來我想到 有試過把換行符號拿掉
也用strlen確定過字串長度只有2
但是還是不行QQ
不過還是謝謝
→
09/28 02:45, , 3F
09/28 02:45, 3F
→
09/28 02:45, , 4F
09/28 02:45, 4F
→
09/28 02:52, , 5F
09/28 02:52, 5F
※ 編輯: momo81 (202.5.249.97), 09/28/2014 03:18:02
→
09/28 07:30, , 6F
09/28 07:30, 6F
→
09/28 07:30, , 7F
09/28 07:30, 7F
windows7
A.txt沒有 就如上面打的那樣
我也是那樣打耶 只是分開
strlen 然後 字串長度的位置-1 = '\0'
那我在試試看好了><
感謝各位
※ 編輯: momo81 (202.5.249.97), 09/28/2014 11:36:44
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章