基本上我有一個緩衝區,其中我正在尋找各種標誌來讀取二進制文件格式的某些領域。我有文件讀入緩衝區,但當我開始編寫代碼來搜索緩衝區的標誌,我立即撞牆。我是一個C++小白,但這裏是我有:將字符數組傳遞給函數|奇怪的錯誤
void FileReader::parseBuffer(char * buffer, int length)
{
//start by looking for a vrsn
//Header seek around for a vrns followed by 32 bit size descriptor
//read 32 bits at a time
int cursor = 0;
char vrsn[4] = {'v','r','s','n'};
cursor = this->searchForMarker(cursor, length, vrsn, buffer);
}
int FileReader::searchForMarker(int startPos, int eof, char marker[], char * buffer)
{
int cursor = startPos;
while(cursor < eof) {
//read ahead 4 bytes from the cursor into a tmpbuffer
char tmpbuffer[4] = {buffer[cursor], buffer[cursor+1], buffer[cursor+2], buffer[cursor+3]};
if (strcmp(marker, tmpbuffer)) {
cout << "Found: " << tmpbuffer;
return cursor;
}
else {
cout << "Didn't Find Value: " << marker << " != " << tmpbuffer;
}
cursor = cursor + 4;
}
}
我的頭看起來像這樣:
#ifndef __FILEREADER_H_INCLUDED__
#define __FILEREADER_H_INCLUDED__
#include <iostream>
#include <fstream>
#include <sys/stat.h>
class FileReader {
public:
FileReader();
~FileReader();
int open(char *);
int getcode();
private:
void parseBuffer(char *, int);
int searchForMarker(int, int, char[], char *);
char *buffer;
};
#endif
我希望找回了使用strcmp VRSN一個比賽,但我的結果看起來像這
Didn't Find Value: vrsn != vrsn
Found:
它看起來像它發現它在第二次通過後,它通過我所期待的字符數組。
相關的十六進制編碼
不應該像'int FileReader :: searchForMarker(...)'{....}? – Recker
* Facepalm *是的,你是corect我是一個白癡 –
修復它。我正在瘋狂 –