Suppose that you have a structure defined as such.

typedef struct Deity
{
    char name[80];
    char religion[80];
    int numAppendages;
} Deity;

And, suppose you have a pointer to a Diety structure.

Deity* deityPtr;

Assuming that at some point you allocate memory for a Deity structure, assign its address to ‘deityPtr’, and fill in the structure’s fields, how would you call printf() so that it will print the numAppendages value of your Deity structure using dietyPtr? (Specifically, what is the syntax for accessing a field within a structure given a pointer to the structure.)

Do you mean this?

#include <string.h>

typedef struct Deity
{
    char name[80];
    char religion[80];
    int numAppendages;
} Deity;

int main(void)
{
	Deity* pDty = new Deity();
	strcpy(pDty->name, "Fred Johnson");
	strcpy(pDty->religion, "Methodist");
	pDty->numAppendages = 6;

	printf("%s\n%s\n%i", pDty->name, pDty->religion, pDty->numAppendages);

	delete(pDty);
	return 0;
}
Member Avatar for MonsieurPointer

Smells like a homework problem...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.