O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Gaining Access to Structure Members

A structure is like a “superarray,” in which one element can be char, the next element float, and the next an int array. You can access the individual elements of an array by using a subscript. How do you access individual members of a structure? Use a dot (.), the structure member operator. For example, libry.value is the value portion of libry. You can use libry.value exactly as you would use any other float variable. Similarly, you can use libry.title exactly as you would use a char array. Therefore, the program uses expressions like

gets(libry.title);

and

scanf("%f", &libry.value);

In essence, .title, .author, and .value play the role of subscripts for a book structure.

Note that although libry is a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required