byte routine not working

This is a discussion on byte routine not working within the C++ Programming forums, part of the General Programming Boards category; ok i am making a byte routine taht searches for a particular byte in a string of bytes. All the ...

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    byte routine not working

    ok i am making a byte routine taht searches for a particular byte in a string of bytes. All the addresses of the found bytes are stored in an array. But its not working and i cant figure out why. Please tell me what i have done wrong:

    Code:
    char *cptr = strchr(bytebuffy, searchnum);
    
    					while(cptr != NULL)
    					{
    						int a = cptr - bytebuffy;
    						Addresses1[g_FoundCount + 1] = readbase + a;
    						g_FoundCount++;
    							
    						cptr = strchr(bytebuffy + a, searchnum);
    					}
    when this runs the windows program just hangs and stops responding as if the while loop wont stop looping

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    > int a = cptr - bytebuffy
    And if this is 0, then

    > cptr = strchr(bytebuffy + a, searchnum);
    Is going to give you the same answer as last time

    Restart your search from the character after the one you've just found.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    It would be easier to do this using the string class.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    49
    Change this line:
    Code:
    cptr = strchr(bytebuffy + a, searchnum);
    to
    Code:
    cptr = strchr(bytebuffy + a + 1, searchnum);
    Hello, everyone.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need loop to copy chunks from byte array
    By jjamjatra in forum C# Programming
    Replies: 2
    Last Post: 03-05-2009, 04:42 AM
  2. Unicode 2 byte wide characters
    By davo666 in forum C Programming
    Replies: 18
    Last Post: 02-22-2009, 04:11 AM
  3. A small Debug routine
    By bftin in forum C++ Programming
    Replies: 1
    Last Post: 09-24-2004, 06:46 AM
  4. Byte confusion!!! HELP!
    By MrDoomMaster in forum C++ Programming
    Replies: 10
    Last Post: 11-12-2003, 03:54 PM
  5. New idea on conveting byte to bits/bits to byte
    By megablue in forum C Programming
    Replies: 10
    Last Post: 10-26-2003, 01:16 AM

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