Question: i have the next code, in which i have a string "hello world" and it has to convert each character into its ASCII value, but instead of printing [68656C.....] it prints some white spaces right after the '[', like this [......68656C]. And i can´t find the reason why

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int i,lon;
    char *cod_maq,*c = {"hello world"},c[2];
    lon = strlen(c);
    cod_maq = (char*)malloc((lon+1)*sizeof(char));
    for(i = 0;i < lon;i++)
    {
        sprintf(c,"%X",c[i]);
        strcat(cod_maq,c);
    }
    printf("[%s]\n",cod_maq);
    return 0;
}

```

thanks

Answer: 
The memory in your malloc already contains data that you need to reset.
malloc allocates memory it doesn't initialize it, so you just get random garbage that was there previously.

```
memset(cod_maq, 0, size_of_cod_maq)

```
`sprintf(c,"%X",c[i]);` : very bad.

fix to like this:

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int i,lon;
    char *cod_maq, *c = {"hello world"};
    lon = strlen(c);
    cod_maq = (char*)malloc((lon*2 + 1) * sizeof(char));//2 required per character
    for(i = 0; i < lon; i++){
        sprintf(cod_maq + i*2, "%02X", c[i]);
    }
    printf("[%s]\n", cod_maq);
    free(cod_maq);
    return 0;
}

```