我試圖在給定文件中找到一個字符串(實際上該文件是tar文件(請注意這裏),並且我在記事本++中打開該文件並隨機抽取從打開的文件中得到一個字符串),然後我將這個完整的tar文件存儲在一個緩衝區中,現在我想查找使用存儲緩衝區中的strstr函數複製的字符串的位置。strstr無法搜索八進制格式數據中的字符串
做的代碼是這樣的(這是絕對正確的) -
char *compare= "_.png"; //suppose this is the copied string
//which is to be find out in buffer using strstr
char * StartPosition;
StartPosition = strstr (buffer,compare);
__int64 count=0;
MessageBox(m_hwndPreview,L"before the while loop",L"BTN WND6",MB_ICONINFORMATION);
while (StartPosition!=NULL)
{
MessageBox(m_hwndPreview,L"hurr inside the while loop",L"BTN WND6",MB_ICONINFORMATION);
MessageBoxA(m_hwndPreview,strerror(errno),"BTN WND4", MB_ICONINFORMATION);
count=StartPosition-buffer+1;
return 0;
}
,並假設如果我有tar文件的內容在記事本一樣從我複製此字符串存儲在compare-
如下3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR (here is some strange data which can't be copied and also there are lot of NULL but we have to find out the position of "_.png" so not so difficult in this case).
的問題是我的代碼運行正常,直到我的巴紐之前的數據存儲,然後我能夠找到使用的的strstr問題的立場是,當我試圖找出哪些是
0之後出現的字符串現在的位置`3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR ...suppose here we have strange data (which is data block if we see the tar parser)...after this we have another file like..."3_VehicleWithKinematicsAndAerodynamics_.html"`
,如果我想找到這個「3_VehicleWithKinematicsAndAerodynamics_.html」用那麼的strstr我不能夠找到它,因爲他們之間的奇怪的數據。(因爲我認爲這些數據不會被編譯器和DUT認可對,我不能夠訪問位於奇怪的數據後) 作出更加明確的文件中看到的tar文件文件的位置如下 -
3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR ............(its data blocl-which is strange contents if you open in tar file)....3_VehicleWithKinematicsAndAerodynamics_.000.html
我要訪問.html文件使用strstr。爲什麼它不訪問它?有任何想法嗎 ?? *
請給替代方案,以實現IT..I我知道我嘗試將不會工作。
我相對確定'strstr'將停在它遇到的第一個'\ 0'字節處。 – arne
您試圖在原始二進制數據上使用字符串函數 - 這肯定不會像您想要的那樣運行 –
您是否有解決此問題的方法?任何其他選擇? – Sss