Thread: concatenating 2 bytes of an array

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    61

    concatenating 2 bytes of an array

    hello,

    I have an unsigned char array which is basically 17bytes long with a null terminator

    in the form 0 0 : 1 1 : 2 2 : 3 3 : 4 4 : 5 5 \0

    i can take the \0 off easily, but i would like to know how i can make a 6 byte array

    in the form 00 11 22 33 44 55


    this is what little code i have so far, however this only creates the 18 byte array which i dont want...
    Code:
    for(iterator = 0; iterator < num_hosts; iterator++){
    	while(i < 17){
    	//printf("%c",return_string[i+1]);
    	bdaddr[i] = return_string[iterator*25+i+1];
    	i++;
    	}
    	bdaddr[17+1] = 0x00;
    	printf("device: %s ",bdaddr);
    	i = 0;
    	//get_device_name(bdaddr, &remote_name);
    	//printf("name: %s\n\n",remote_name);
    }
    thanks for your help

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Use strtok() - check out this FAQ link that explains with code how to extract substrings delimited by tokens.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. concatenating two bytes into an uint16
    By davo666 in forum C Programming
    Replies: 11
    Last Post: 01-07-2009, 11:43 PM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Concatenating strings (dynamic array using pointers)
    By Tankndozer in forum C Programming
    Replies: 8
    Last Post: 07-01-2004, 07:27 AM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. Couldn't stop!
    By cockroach007 in forum C Programming
    Replies: 1
    Last Post: 10-13-2001, 08:52 AM