Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- char *to_hex_string(void *input, size_t input_length) {
- char *o = (char*) malloc(input_length * 2 + 1);
- for (size_t i = 0; i < input_length; i++) {
- sprintf(o + i * 2, "%02x", ((uint8_t*)input)[i]);
- }
- o[input_length * 2 - 1] = '\0';
- return o;
- }
- int main() {
- char *c1 = to_hex_string(u8"hello world", 11);
- char *c2 = to_hex_string(u"hello world", 22);
- char *c3 = to_hex_string(U"hello world", 44);
- printf("UTF-8:\n%s\nUTF-16:\n%s\nUTF-32:\n%s\n", c1, c2, c3);
- free(c1);
- free(c2);
- free(c3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement