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!

How do i print 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.
 
#include <stdio.h>

#define NAME_MAX 100

typedef struct obj
{
char nm[NAME_MAX];
struct obj *in;
} obj;

int main( void )
{
obj firstObj;
obj secondObj;

strcpy( firstObj.nm,&quot;This is first struct...&quot; );
strcpy( secondObj.nm,&quot;This is second struct...&quot; );

firstObj.in= &secondObj;

printf( &quot;%s\n&quot;,firstObj.nm );
printf( &quot;%s\n&quot;,firstObj.in->nm );

return 0;
}

Mike L.G.
mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top