0

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.)

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by MonsieurPointer
0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.