c - Pointer as parameter is null but after function pointer is not null -
this question has answer here:
hello have funcion like:
void enterstring(char *string) { string = (char*)malloc(15); printf("enter string: "); scanf("%s",string); //don't care length of string } int main() { char *my_string = null; enterstring(my_string); printf("my string: %s\n",my_string); /* it's null want show string typed enterstring */ return 0; }
i want string function show on string in main ... don't know if you'll understand me. thank :)
you passing string value. neet pass address :
void enterstring(char **string) { *string = (char*)malloc(15); printf("enter string: "); scanf("%s",*string); //don't care length of string //you should! } int main() { char *my_string = null; enterstring(&my_string); printf("my string: %s\n",my_string); free(my_string); return 0; }
Comments
Post a Comment