A
Angus Comber
Hello
My code below opens a Word document in binary mode and places the data into
a buffer. I then want to search this buffer for a string. I tried using
strstr but think it stops looking when it reaches first null character or
some control character in data. What C function should I use to be able to
search in a BYTE data buffer?
Code:
#include <stdio.h>
char szPath[MAX_PATH] = "";
strcpy(szPath, "E:\\MyPath\\ahl.doc");
FILE* stream;
FILE *file = fopen(szPath, "rb"); // Open the file
fseek(file, 0, SEEK_END); // Seek to the end
long file_size = ftell(file); // Get the current position
rewind (file); // rewind to start of file
// allocate memory to contain the whole file.
BYTE* byBuffer = (BYTE*) malloc (file_size);
// if (buffer == NULL) exit (2);
// copy the file into the buffer.
fread (byBuffer,1,file_size, file);
const char* szFind = "selected";
//strstr(StrToLookIn, StrToFind);
char* szResult = strstr((char*)byBuffer, szFind);
fclose(file); // Close the file
free( byBuffer );
Angus Comber
(e-mail address removed)
My code below opens a Word document in binary mode and places the data into
a buffer. I then want to search this buffer for a string. I tried using
strstr but think it stops looking when it reaches first null character or
some control character in data. What C function should I use to be able to
search in a BYTE data buffer?
Code:
#include <stdio.h>
char szPath[MAX_PATH] = "";
strcpy(szPath, "E:\\MyPath\\ahl.doc");
FILE* stream;
FILE *file = fopen(szPath, "rb"); // Open the file
fseek(file, 0, SEEK_END); // Seek to the end
long file_size = ftell(file); // Get the current position
rewind (file); // rewind to start of file
// allocate memory to contain the whole file.
BYTE* byBuffer = (BYTE*) malloc (file_size);
// if (buffer == NULL) exit (2);
// copy the file into the buffer.
fread (byBuffer,1,file_size, file);
const char* szFind = "selected";
//strstr(StrToLookIn, StrToFind);
char* szResult = strstr((char*)byBuffer, szFind);
fclose(file); // Close the file
free( byBuffer );
Angus Comber
(e-mail address removed)