Divide once and then Merge again
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Divide once and then Merge again

  1. #1
    Join Date
    Dec 2003
    Posts
    220

    Divide once and then Merge again

    If I have a file 1000Kb, I would like to divide it into 2 part 50-50, can you tell me how to do that ? Is it possible ?
    If it is, then how can I "heal" it again ?

    Thanks a lot,

    Regards,
    homestead

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060
    Mmm, i don't quite understand what you are trying to do

    You can just open your 1000kb file in binary mode, read and write 500 kb of it to a new file and the last 500 kb to another file.
    To merge them, just open the first part in binary, copy it to the new merged file. Then open the second part and append that to the new merged file.

  3. #3
    Join Date
    Dec 2003
    Posts
    220

    Thanks Marc G for telling me that my question is unclear and giving me ideas...

    Originally posted by Marc G
    Mmm, i don't quite understand what you are trying to do

    You can just open your 1000kb file in binary mode, read and write 500 kb of it to a new file and the last 500 kb to another file.
    To merge them, just open the first part in binary, copy it to the new merged file. Then open the second part and append that to the new merged file.
    hahahu...
    But now I understand how to solve this problem....
    I d like to ask another question : do you know why people gurus like you keep saying about modes(binary, some.others.I.dont.know.yet) what is a mode ? why is it necessary ? does mode help me do what ?

    Thanks again,

    Regards,

    homestead

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060
    Note: I only speak about Windows.

    If you have a text file, then each line should end with \r\n or \n.
    When you open a text file in text-mode, each \n will be replaced with \r\n. When you open the file in binary-mode, no such conversion takes place.
    Conclusion: When you do not want conversions to happen behind your back, open the file in binary. Because you said you wanted to split the file in 2 and then merge them back in one, you want the resulting file to be exactly like the original, don't you. Therefore open the file in binary, and no conversion will take place.

  5. #5
    Join Date
    Dec 2003
    Posts
    220
    Originally posted by Marc G
    Note: I only speak about Windows.

    If you have a text file, then each line should end with \r\n or \n.
    When you open a text file in text-mode, each \n will be replaced with \r\n. When you open the file in binary-mode, no such conversion takes place.
    Conclusion: When you do not want conversions to happen behind your back, open the file in binary. Because you said you wanted to split the file in 2 and then merge them back in one, you want the resulting file to be exactly like the original, don't you. Therefore open the file in binary, and no conversion will take place.
    (ha)^n.(n->infinity)
    I mean I laugh alot, now I know about binary mode, but actually I dont care about conversions.
    Thanks so much for your help, I will try to remember all of what you said...

    Regards,

    Fiona

    I care about this, no matter HOW and what it is, just think I am guilty and from now I gotta do something to repay...That cant be but another different form can ...<--If you dont understand, forget it, I want that reader to undestand this and that s all !!!
    Attached Images Attached Images  
    Last edited by Homestead; January 3rd, 2004 at 01:28 PM.

  6. #6
    Join Date
    Sep 2000
    Location
    Russia
    Posts
    262
    Hi Homestead,

    I just wanted to tell you that in my opinion Marc G gave you a clear answer to your question.
    You wrote your question in human language, that meant you needed the algo to resolve that problem. You got that algo from Marc G.
    Did you consider you would get a ready-to-compile program text? Some of the members of these forums do sometimes do so, but would that be of use to you?
    If you just want to solve your task of splitting and merging a file you can use one of a number of utils that you can find over the inet. Otherwise, if you want to learn C++ this way, try it step-by-step. At least one line of code would be enough for the community to start helping you.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center