Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(void)
  6. {
  7.     char *buffer = "0x000x220x680x150x710xc60x420x09";
  8.     char single_byte[4 + 1]; //4 bytes + 1 byte for NULL character
  9.     int *pkt;
  10.     int i = 0;
  11.  
  12.     pkt = (int *)malloc(strlen(buffer)/4); //you can take an array of desired size if you want
  13.     if (!pkt) {
  14.         perror("malloc failed");
  15.         exit(1);
  16.     }
  17.  
  18.     while (*buffer != '\0') {
  19.         memset(single_byte, 0, sizeof(single_byte)); //create a NULL terminatied string
  20.         strncpy_s(single_byte, sizeof(single_byte), strstr(buffer, "0x"), 4);
  21.         buffer += 4;
  22.         sscanf_s(single_byte, "0x%x", &pkt[i++]);
  23.     }
  24.  
  25.     exit(0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement