While Loop Conditions?

This is a discussion on While Loop Conditions? within the C Programming forums, part of the General Programming Boards category; Hi Firslty, my first post, and I'm new to C programming. Secondly, I'm not overly bright so please bare with ...

  1. #1
    Registered User ted_smith's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    4

    Unhappy While Loop Conditions?

    Hi

    Firslty, my first post, and I'm new to C programming. Secondly, I'm not overly bright so please bare with me!!

    I have a character array assigned of 1024 bytes in length to hold 1024 characters. This is to read in the MFT record headers, one at a time, of a Windows MFT File.

    I know that each MFT record begins with the characters 'FILE', (46h, 49h, 45h, 2Ah in Hex). What I want to do is to tell my while loop to continue until the first 4 bytes of the 1024 do not equal the chars FILE (because once this happens the program has reached the end of the MFT).

    I am really stuck, and don't really know how to achieve what I want to do . I know I need a while or for loop, but I'm unsure how to go about it.

    I have my input file specified as follows :

    Code:
    if
       ((FileIn = fopen("C:\\DriveImage.1", "rb")) == NULL)      //the use of \\ is to ensure escape char used after the \ of c:\. fopen enters the content of the file into RAM. "rb" is to READ a BINARY file for reading & writing
        {
         printf ("Unable to open binary file. Please try again. \n");
         getch ();
         exit(0);
        }
     else
        {
         printf ("Input File opened successfully\n");
         getch();
        }
    Then,
    Code:
    OffsetValueOfMFT = ((1373544 * 512) + (63 * 512)); /*A byte value is required for fseek function.
                                                           343386 (hex value 00 00 00 00 00 05 3D 5A - from offset 0x30) x 4 = 1373544
                                                           1373544 x 512 = 703254528
                                                           703254528 + (63 x 512) = 703286784
                                                           703286784 in hex is 29 EB 4E 00 - the physical offset of MFT  */
    
      rewind(FileIn);
      fseek (FileIn, OffsetValueOfMFT, SEEK_SET);        //Look at input file, and set seek point to the start of the MFT, i.e. value of OffsetValueOfMFT
    
    ftell(FileIn);                                     //returns the location of the file position indicator for the file specified by FileIn
      CurrentPosition = ftell(FileIn);
      memset(MFTBufferArray, 0x00, 1024);                //clear the buffer
    Then I'm stuck.

    Any guidance much appreciated!

    Thanks

    Ted
    Last edited by ted_smith; 01-15-2005 at 09:32 AM. Reason: Ammendments to code

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    India
    Posts
    515
    try this out-> first get in the first four bytes using say a for loop to loop 4 times. compare for the FILE thing and then if its FILE, then go ahead and copy to the array.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    Registered User ted_smith's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    4
    While I was waiting I have done the following :

    Code:
    memset(MFTBufferArray, 0x00, 1024);                //clear the buffer
      fread(MFTBufferArray, 1, 1024, FileIn);            //read in 1024 bytes from FileIn and store them in the buffer array
      fwrite(MFTBufferArray, 1, 1024, FileOut);
    
    
      CurrentPosition = ftell(FileIn);                   //returns the location of the file position indicator for the file specified by FileIn
      printf("The Current position is %d", CurrentPosition);
      getch();
      fclose(FileIn);
      fclose(FileOut);
    Now, this works a treat in that the first 1024 bytes are written to my output text file. Great. However, I need it to

    a) look at the next 1024 bytes but only if
    b) the first 4 bytes of the next 1024 bytes equal the characters FILE.

    To help you see what I mean, here is a sample of an MFT extract :

    Code:
    FILE*...G........0...............................`...........H.......pP.pP.pP.pP.
    FILE*.............0...P...........................`...........H.......pP.pP.pP.pP
    FILE*...4..........0...P...........................`...........H.......pP.pP.pP.pP
    I don't know how to do that. Any suggestions?
    Last edited by ted_smith; 01-15-2005 at 10:04 AM. Reason: To provide example of MFT extract

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's a novel idea, why don't you read four bytes, see if it's F I L E, if so, read another 1020 bytes?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User ted_smith's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    4
    That is what I do want to do - what I need to know is how do I do that?

  6. #6
    Registered User
    Join Date
    Nov 2004
    Location
    India
    Posts
    515
    thats what i told you in my post. first a loop to loop 4 times, and then check the conditions and go in for the next 1020 bytes. simple as that.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  7. #7
    Registered User ted_smith's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    4
    It's the syntax that I don't know though - I'm fine with the concept - just don't know how to do it using C syntax.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    India
    Posts
    515
    read the FAQ and the tutorials for the syntax.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You've shown how to read 1024 bytes, using fread, so why don't you just check the first four bytes of what you read to see if it's what you want. Just throw that in a loop. Or, change it, and read 4 bytes instead of 1024, and check that. I don't see how you can be stuck on this, since you've all ready illustrated that you know how to read.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'For loop' looping one too many times.
    By thealmightyone in forum C Programming
    Replies: 7
    Last Post: 02-20-2009, 05:46 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  3. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 06:19 AM
  4. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21