Hello I have some trouble with pointer !
#include <stdio.h>
#include <stdlib.h>
void test(char **str)
{
*str = (char *)malloc(sizeof(char) * 2);
*str[0] = 'b';
*str[1] = '\0';
}
int main(void)
{
char *str;
test(&str);
printf("%s\n", str);
return (0);
}
So I pass a pointer of an non allocated string in my function test, then I allocate my string in the function and try to manipulate it but this code segfault so I guess I miss something on my pointer lesson :)
Can you help me to figure out what is happening here ? thank you a lot !
edit : when I remove my return (0) in the main, the code compile and display my char * ! super weird