Thread: Inserting hex byte into a data

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Question Inserting hex byte into a data

    URGENT: NEED HELP

    I have this situation where I need to insert hex byte type into a data, but my code doesn't work out as expected, that it only worked once. This is how the problem:

    E.g.:

    unsigned char data[10] = "\x50\x10\x30\x20\x17\x9A\x00\x10";

    //insert and produce "\x50\x10\x10\x30\x20\x17\x9A\x00\x10\x10"

    I have used loop to do so, but it only applicable to insert once, but not twice or more. Searching for any opinions and alternatives. Please reply. Thanks.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    I have used loop to do so, but it only applicable to insert once, but not twice or more.
    Show the code that works only once
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Code:
    void main(){
    
           int i, j=0;
           BYTE dataBuf[20] = "\x90\x50\x80\x10\x10\x90\x10\x99\x1A"; //3,4,6
           BYTE cBuf[10]; //counter
           BYTE sBuf[20],outBuf[20]; 
    
           for(i=0; i<9; i++)
    	{
    	       if (bBuf[i] == 0x10){
                       cBuf[j] = i;     //using reference index
                       j++;  		
                   }
    	}
    
           memcpy(sBuf, dataBuf,sizeof(sBuf));
           for(i=0; i<j; i++)
    	{	        			
    		memcpy(&sBuf[cBuf[i]], &bBuf[cBuf[i]-1], sizeof(sBuf));				
    	} 
            
    }

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    bBuf is not define

    I do not understand what you are doing at all

    and could you describe what in this code does not work? And what it should be

    Also note that main should be

    int main(void) - read FAQ
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    The problem is fixed. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  2. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  3. ANSI C ASCII String to HEX byte array conversion
    By phyte in forum C Programming
    Replies: 10
    Last Post: 12-14-2004, 08:02 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM