How would I go about doing this? I have a structure pointer and inside the structure is a pointer to a char. Here is what I have sofar, but it crashes.
Code:#include <stdio.h> char doug[] = "Doug"; struct structure { char* name; }*struct_ptr; int main() { struct_ptr->name = &doug[0]; // This causes the freezing printf("%s",*struct_ptr->name); return 0; }
I know that the problem is the assigning of the address of the string to the structure, but I don't know how to fix that. Thanks in advance.
I searched and searched google, this site, and other references, but I haven't come across how to assign the address of a char to a member exactly like the above example.



LinkBack URL
About LinkBacks







