Click here to Skip to main content
15,891,529 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Function pointer problem Pin
David Crow20-May-11 7:16
David Crow20-May-11 7:16 
AnswerRe: Function pointer problem Pin
Albert Holguin20-May-11 8:08
professionalAlbert Holguin20-May-11 8:08 
GeneralRe: Function pointer problem Pin
David Crow20-May-11 8:12
David Crow20-May-11 8:12 
GeneralRe: Function pointer problem Pin
Albert Holguin20-May-11 9:24
professionalAlbert Holguin20-May-11 9:24 
AnswerRe: Function pointer problem Pin
smags1320-May-11 7:43
smags1320-May-11 7:43 
GeneralRe: Function pointer problem Pin
Albert Holguin20-May-11 10:02
professionalAlbert Holguin20-May-11 10:02 
AnswerRe: Function pointer problem Pin
Paul Michalik20-May-11 23:10
Paul Michalik20-May-11 23:10 
QuestionSearch for bytes array in a binary file Pin
Smart Arab20-May-11 5:39
Smart Arab20-May-11 5:39 
Hello , could you please help me with this ?

I have wrote the following code which open a file ( binary file )
Search for bytes sequence and return the position at first occurs ,
It's work in some cases , like if file fill's with Zero's and my searched bytes only !
and it's give me headache !

Here is my code :
int main()
{
	unsigned int data[6] = {
	0x11, 0x22, 0x33, 0x44, 0x55, 0x66
	};
	
	cout << "pos : "  << FindBytes(data , 6 , "c:\\test.a") << endl;
	return 0;
}


The Function :
int FindBytes ( unsigned int data [], int datalength,  char *filename )
{
	FILE *file;
	file = fopen(filename, "r");
	
	int pos = 0;
	int length = datalength - 1;
	int ch;
	int cpos = 0;
	
	do
	{
		ch = getc(file);
		if(ch == data[0])
		{
			pos += length - 1;
			fseek(file , pos , SEEK_SET);
			ch = getc(file);
			if(ch == data[length])
			{
				for(int i = 0;i <= length;i++)
				{
					cpos = pos - length + i;
					fseek(file, cpos, SEEK_SET);
					ch = getc(file);
					if(ch != data[i])
					{
						fseek(file , cpos, SEEK_SET);
						goto resume;
					}
				}
			    return pos - length;
			}
		}
		else
		{
			resume:
			fseek(file, pos, SEEK_SET);
		}
		pos++;
	}
	while ( ch != EOF );

	return -1;
}


thank you ,
AnswerRe: Search for bytes array in a binary file Pin
Albert Holguin20-May-11 5:47
professionalAlbert Holguin20-May-11 5:47 
GeneralRe: Search for bytes array in a binary file Pin
Smart Arab20-May-11 6:04
Smart Arab20-May-11 6:04 
GeneralRe: Search for bytes array in a binary file Pin
David Crow20-May-11 7:54
David Crow20-May-11 7:54 
AnswerRe: Search for bytes array in a binary file [modified] Pin
Albert Holguin20-May-11 7:54
professionalAlbert Holguin20-May-11 7:54 
QuestionHow do I update a Form from a function? Pin
Freddie Code20-May-11 4:53
Freddie Code20-May-11 4:53 
AnswerRe: How do I update a Form from a function? Pin
Freddie Code20-May-11 6:43
Freddie Code20-May-11 6:43 
Questiondamage after normal block( #24094) Pin
Sakhalean20-May-11 0:45
Sakhalean20-May-11 0:45 
AnswerRe: damage after normal block( #24094) Pin
Chris Losinger20-May-11 0:56
professionalChris Losinger20-May-11 0:56 
AnswerRe: damage after normal block( #24094) Pin
Malli_S20-May-11 1:18
Malli_S20-May-11 1:18 
Questionmatrix Rotation Pin
002comp20-May-11 0:08
002comp20-May-11 0:08 
AnswerRe: matrix Rotation Pin
Luc Pattyn20-May-11 1:42
sitebuilderLuc Pattyn20-May-11 1:42 
GeneralRe: matrix Rotation Pin
002comp20-May-11 2:56
002comp20-May-11 2:56 
JokeRe: matrix Rotation Pin
David Crow20-May-11 3:06
David Crow20-May-11 3:06 
QuestionFile creation time Pin
tasumisra19-May-11 22:56
tasumisra19-May-11 22:56 
AnswerRe: File creation time Pin
Richard MacCutchan19-May-11 23:18
mveRichard MacCutchan19-May-11 23:18 
GeneralRe: File creation time Pin
mosealex20-May-11 3:55
mosealex20-May-11 3:55 
GeneralRe: File creation time Pin
Richard MacCutchan20-May-11 4:23
mveRichard MacCutchan20-May-11 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.