Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:30:18+00:00 2026-06-12T09:30:18+00:00

Basically I have a buffer in which i am looking for various flags to

  • 0

Basically I have a buffer in which i am looking for various flags to read certain fields from a binary file format. I have file read into a buffer but as i started to write code to search the buffer for the flags i immediately hit a wall. I am a C++ noob, but here is what i have:

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;
  }
}

my header looks like this:

#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

I would expect to get back a match for vrsn with strcmp but my result looks like this

Didn't Find Value: vrsn != vrsn
Found: 

It looks like it finds it on the second pass after its passed the char array i am looking for.

Relevant hexcode

hex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:30:19+00:00Added an answer on June 12, 2026 at 9:30 am

    Shouldn’t that be something like int FileReader::searchForMarker(...) { .... }?

    For the second query, I guess the strcmp works when it has two null terminated strings as its arguments. For example str1[]="AAA"; and str2[]="AAA"; then strcmp() would be used as
    if(strcmp(str1,str2)==0) which will return 0 to indicate that they are equal. In your case, the tmpbuffer that you have created is not a null terminated string unless you add \0 in the end.So you might want to add \0 in the end of your tmpbuffer to create a string of 'v' 'r' 'n' 's'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically i am reading image bytes from file i have a loop which has
I basically have a program that filters records from one excel file to another
Basically I have void FileReader::parseBuffer(char * buffer, int length) { //start by looking for
I have an app that loads records from a binary log file and displays
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I have a logger system which basically is a fancy way of writing my
I have a small (desktop) application which basically consists of an user-friendly CRUD interface
I am trying to read data from a HID device. I have a USB
I have a section on my Android app called 'More Information' which is basically
I want to read the pixels from the back buffer. But all i get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.