Thread: hit a stumbling block in program

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    99

    hit a stumbling block in program

    hi, i have hit a stumbling block in a program i am trying to create and i cannot get round it. Kind of related to a previous post a while ago but ive come across a different problem. I have put the basic structure of my code below but i starts by positioning myself in a file at STARTOFROOT variable. From the variable i parse through 16384 bytes of data in differnet chunk sizes. Anyway ive got this part sorted however im having trouble with the next part. At various points in the 16384 bytes i will come across bytes that contain a flag value which basically will point to another part of my file for which i need to start the whole process again but at a new value given to STARTOFROOT. I tried implimenting 'if' statements into the code at these various points but it just got out of hand and messy.

    My other problem is these new values can appear any number of time and at any point within the 16384 bytes. Therefore if itt appears at the first 100 bytes and i pass the new value to STARTOFROOT then i miss out processing the rest of that particular section as the file stream moves to the next part of the file.


    I hope im explaining myself well enough here but on paper I seem to think a solution would be process all the bytes in the first section. Whilst processing make a note of each flag that contains a value to move to a new part of the file. Then go to each of these values and repeat the process again for each new place.......i think the word im looking for is "recursive?"

    Im having real problems developing a sensible solution for this and i was hoping that maybe you guys could suggest any ideas/advice?


    Code:
    f.seekg(STARTOFROOT)   //starts at a particular point in a file
    
    
    for loop (for 16384) 
    
    //{
    
    
    
    Processing the files in differnent sized chunks depending on what values each byte has
    
    
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Recursion is one way.

    Adding a "work queue" would work as well. As you find extra entries to process, you add them to the queue, and carry on with the current block.

    At the end of the block, look in the queue to see if anything else needs to be done.
    When the queue is empty, you're done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    That sounds spot on that does! I think il have a look at queues because i think they could solve my problem!

    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  3. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  4. Bug in Program - please help!
    By muffin in forum C Programming
    Replies: 4
    Last Post: 08-31-2001, 09:33 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM