Thread: How do I read in five bytes and compare the first four and if it is ok then keep

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    150

    How do I read in five bytes and compare the first four and if it is ok then keep

    the last byte and read in four more while keeping the last byte of the previous set in first place of the new set?
    And if it is not ok then write out all five bytes to a file?
    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about you write that out in steps before you start trying to program it?


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

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    I'm not sure how to.
    I need to read in five bytes and look at the data if I come accross a certain symbol in hex only write out the first two or three or four keeping the remander for the buffer and refill the rest of the buffer.
    Thanks
    Last edited by Once-ler; 02-08-2012 at 03:42 AM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you can't plan out in words what steps you would need to do, then you have no hope of programming it. Think about it in simple abstract steps, not in actual code.


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

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    If first byte = A & second byte = A but third byte != A then write out AA(whatever the value of the third byte), and read in three more bytes behind the leftovers.
    If first byte !=A then write out the five bytes and read in five new fresh ones.
    Last edited by Once-ler; 02-08-2012 at 05:36 AM.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    Or how about this, I need to write a program that reads hex values from 4 bytes. If the values of the first one is ! A then output the 4 bytes to a file, If it ==A and the second byte == A but the tird byte != A then output the 3 bytes.
    I'm sorry I don't really know how to explain it very good.
    I am still a newbie.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The reason I didn't just start handing out code was because you need to learn how to describe in detail what you really need, and then to break those things into small tasks.
    Code:
    open one file for reading, call it input
    open one file for writing, call it output
    while there is still stuff in the input file, do this:
        1. Check for the appropriate bytes.
        2. Write if we have a match.
    close both files
    Now, you have to break each of those steps into as many small tasks as you need to, so that each step you need to do is as clear as possible. Once you understand all of the steps, you can think about coding it.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bytes lost with partial read in UDP
    By mynickmynick in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-31-2009, 02:06 AM
  2. how to read 4 consecutive bytes as an integer
    By *DEAD* in forum C Programming
    Replies: 8
    Last Post: 01-15-2007, 04:03 PM
  3. read 2 bytes from a file...
    By compile in forum C Programming
    Replies: 10
    Last Post: 10-17-2006, 12:54 AM
  4. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  5. Read Bytes From File Into Integer
    By ChadJohnson in forum C Programming
    Replies: 28
    Last Post: 08-16-2004, 11:57 AM