Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(void)
- {
- char *buffer = "0x000x220x680x150x710xc60x420x09";
- char single_byte[4 + 1]; //4 bytes + 1 byte for NULL character
- int *pkt;
- int i = 0;
- pkt = (int *)malloc(strlen(buffer)/4); //you can take an array of desired size if you want
- if (!pkt) {
- perror("malloc failed");
- exit(1);
- }
- while (*buffer != '\0') {
- memset(single_byte, 0, sizeof(single_byte)); //create a NULL terminatied string
- strncpy_s(single_byte, sizeof(single_byte), strstr(buffer, "0x"), 4);
- buffer += 4;
- sscanf_s(single_byte, "0x%x", &pkt[i++]);
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement