Read binary file with line delimeter - Page 4
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 11 FirstFirst 1234567 ... LastLast
Results 46 to 60 of 156

Thread: Read binary file with line delimeter

  1. #46
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,738

    Re: Read binary file with line delimeter

    Now, I only need to add the function of process that will parse each block within the while loop rigth?

    I'd like to parse each block using regex.
    What parsing of the block do you require?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  2. #47
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello AceInfinity,

    Thanks for try to help me too. I'll test your code either.

    Hello 2kaud,

    For each block I'd like first to extract some patterns with 2 regex below.
    Regex1: (.{6,18})(532064[^f]*).(814[^f]*)
    Regex2: ff79(0080.{4}c906)?.*?05(9.{32,34}.*?)940e(.{28})

    Regex1 matches string in red
    Regex2 matches string in blue

    Code:
    00000253206445018934551f81474554768fffff0015000a4800015a00024200016000013300013600013700015b00016600
    016500017700017800017e00016900006a00007900009300012200002100010900010a001260001020001040001050001060
    0011000010800012b00002c00012d00012e00015500015600072a00002f0000300000310000ff7900800932c90688888000a
    000800935c90600008000000080093cc90688888000000800943c90688888000800005900f0102000000308147526905ffff
    ff00910f01020000013a81475269559fffff009310010c0000009f8147526905ffffff0101960f010e000000eb8147526959
    6fffff00970f0100006f69981475269563fffff00940e0001000001000100ffff0000010195060003790001ea05820037060
    10000010065000000020000020018000000030000030017000000040000040001000000050000050015000000a00ffff0065
    00000007802ec918009181475269539fffffff009181475269539fffff000103ca030808fecb0a00000000000000000000cc
    0101811bc90b009181475269567fffffffca06000000000000cb0103cc0101
    Regex1 works to extract data from the beginning of the block, for block 2 Regex1 would get:
    Code:
    00000253206445018934551f81474554768
    but since I'm grouping with backreference, this string would be splitted like this
    Code:
    000002,53206445018934551,81474554768
    to finally treat as hex the first group and print as decimal, leaving group 2 and group 3 without change as below.
    Code:
    2,53206445018934551,81474554768
    For Regex2, I'm using backreference too, since I only want to extract the group 2 and 3 from Regex2. But the
    parsing of string got from Regex 2 is more complicated. So, Initially I'd like to know how to apply regex on each
    block.

    Many thanks for the help

  3. #48
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,738

    Re: Read binary file with line delimeter

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #49
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello 2kaud,

    Thanks for that.

    I've tried to add <regex> header but I receive error. I've read that maybe with visual studio compiler could work.

    I've downloaded and installed a visual C++ 2012 compiler version but I'm no able to make that works with netbeans nor Dev C++.

    Does accepts for you the regex header? Which IDE and compiler are you using?

    Thanks in advance

  5. #50
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: Read binary file with line delimeter

    I'm using VS 2013 and am able to use the <regex> header with this setup. Dev C++ is old (assuming you're using bloodshed's, and not orwells), and if so, you should abandon it.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  6. #51
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Thanks for the answer.

    I'm testing with netbeans and Orwells Dev C++.

    Since MSVS is payed, do you know another IDE or compiler that let me use regex?

    Thanks again

  7. #52
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: Read binary file with line delimeter

    Quote Originally Posted by Philidor View Post
    Thanks for the answer.

    I'm testing with netbeans and Orwells Dev C++.

    Since MSVS is payed, do you know another IDE or compiler that let me use regex?

    Thanks again
    You're assuming that it's a paid software. There are express editions of Visual Studio for 2013 which are free.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  8. #53
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello Ace

    I've installed MSVS 2013 and I've been trying to test regex using the example for the below page, bu I get errors when
    compile.
    http://en.cppreference.com/w/cpp/reg...ax_option_type

    I'm not sure why, I did this: New project --> Visual C++-->CLR-->CLR Console Application.

  9. #54
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: Read binary file with line delimeter

    CLR, why do you want that? Try "Win32 Project" instead. What errors are you getting? You just posted a reference link, but nothing that describes the errors.
    Last edited by AceInfinity; October 15th, 2013 at 01:02 AM.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  10. #55
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,738

    Re: Read binary file with line delimeter

    Since MSVS is payed, do you know another IDE or compiler that let me use regex?
    gcc is free and is c++11 compliant
    http://gcc.gnu.org/

    (see top of news left hand side regarding support for regex!)
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #56
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Quote Originally Posted by AceInfinity View Post
    CLR, why do you want that? Try "Win32 Project" instead. What errors are you getting? You just posted a reference link, but nothing that describes the errors.
    Thanks!. Only I didn't know what option to choose. I'll test as you say.

    Quote Originally Posted by 2kaud View Post
    gcc is free and is c++11 compliant
    http://gcc.gnu.org/

    (see top of news left hand side regarding support for regex!)
    Thanks 2kaud, I'll try to download and see if I'm able to make it work this compiler.

    Thanks again for the help.

  12. #57
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello 2kaud

    I've been searching and it seems gcc doesn't support yet regex . It seems only basic things.

    http://gcc.gnu.org/projects/cxx0x.html
    http://gcc.gnu.org/onlinedocs/libstd...tatus.iso.200x

    I found that clang is full C++11, but it seems it works for linux. I'll continue searching.

  13. #58
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello 2kaud again,

    I see that each block is printed in the for loop using "display(bv)", but I'd like to store in a single string each block
    to be able to process it. I'd like to modificate the display function in order to have in a string each block, something like
    below but I don't know how would be the correct way and how to retrieve that string in main function.
    Code:
    void display(const bVec bv)
    {
    	for (int i = 0; i < bv.size(); i++)
    		//cout << setw(2) << setfill('0') << hex << (int)bv[i];
    	    Block= Block + (int)bv[i];
    }
    I hopw you can help me with this.

    Thanks in advance.

  14. #59
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,738

    Re: Read binary file with line delimeter

    bv is a vector of BYTE (unsigned char) that can be processed. If you want a string of hex equivalent then one way is

    Code:
    void display(const bVec& bv)
    {
    	for (int i = 0; i < bv.size(); i++)
    		cout << setw(2) << setfill('0') << hex << (int)bv[i];
    	
    	cout << endl << endl;
    }
    
    void conString(const bVec& bv, string& block)
    {
    ostringstream ss;
    
    	for (int i = 0; i < bv.size(); i++)
    		ss << setw(2) << setfill('0') << hex << (int)bv[i];
    
    	block = ss.str();
    }
    
    int main()
    {
    FileFields	ff;
    
    bVec	bv;
    
    int blk = 0;
    
    string block;
    
    	if (!ff.open("binary.txt")) {
    		cout << "Cannot open file!" << endl;
    		return 1;
    	}
    
    	while (ff.getField(bv)) {
    		cout << "block " << blk++ << endl;
    		//display(bv);
    		conString(bv, block);
    		cout << block << endl << endl;
    	}
    
    	return 0;
    }
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  15. #60
    Join Date
    Oct 2013
    Posts
    63

    Re: Read binary file with line delimeter

    Hello 2kaud,

    Thanks for your help. Ive tried but in compilation I get the error:

    Code:
    [Error] aggregate 'std::ostringstream ss' has incomplete type and cannot be defined
    I've added "std::" but the same error.

Page 4 of 11 FirstFirst 1234567 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center