Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help on printing out strings using pointers.

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
I wish to print out a string. I have a pointer to another pointer that contains my string.

first pointer: playerptr->in
points to the in field within the structure:

typedef struct obj {

char nm[NAMEMAX];
char desc[DESCMAX];
struct obj * in;
struct obj * n;
struct obj * s;
struct obj * e;
struct obj * w;

} obj;

I can print out the nm and desc, but not in, n, s, etc....
I print out nm using:
printf("Name: %s", playerptr->nm);
But this doesnt work for in, n, etc..... as they are pointers.
I think it just prints out a memory address for these.

Please help, i'm really stuck.

Thanks.

Mark.
 
Hi,
You have to give the member of the class for printing;
like, playerptr->in->member_of_in.

-Bala S
 
Very rightly parnis, if I may add,
Code:
'in'
being a pointer needs to be allocated memory of size obj. Only then the assignments to the inner pointers would work properly.

may be something like this:
Code:
playerptr->in=(obj *) malloc(sizeof(obj));
strcpy(playerptr->in->nm,"Some String!");

printf("Name: %s", playerptr->in->nm);

and there on... I hope I didnt confuse u further...;-)

have fun coding...B-)

Roy.
user.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top