開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
問題(Question):
我有一個B字串跟一個A字串
那我想知道,B字串在A字串中的位置(不管B有沒有出現在A)
所以我使用strstr來處理
int location;
char str_A[20]="Hello world.",str_B[6]="Error";
location=(int)(strstr(str_A,str_B)-str_A);
if(location<0)
return -1;
else
return location;
如果找不到,應該相減後會為負數
但是在Linux下偶爾相減後卻是一個非常大的正數
導致程式判斷就錯誤了,但是Windows卻不會
我是哪邊寫錯或是哪邊需要修改,才能符合我所預期的功能呢?
再麻煩高手幫忙一下,感謝