-
Easy Pointer question
char string[30];
char *ptr_string;
how do i copy ptr_string and put it into string?
like this?
Code:
string = strdup(ptr_string);
what about the other way?
Code:
ptr_string = strdup(string); ? or is it
ptr_string= (char *)malloc (strlen(string) * sizeof(char));
-
The way strdup() is described, you'd do something like:
Code:
ptr_string = strdup(string)
but by the way you worded the question you want it assigned the other way around? There is no storage allocated for ptr_string yet. Only the array string[] has storage so far. Your guesses seem to be more like what I have. strdup does an implicit malloc for you.