C examples for Structure:Structure Value
Create and use Nested Structures
#include <stdio.h> #define LEN 20/*from w w w . j a v a2 s .co m*/ const char * msgs[5] = { "this is a test, ", "thanks ", "new ", "title ", " and examples" }; struct names { // first structure char first[LEN]; char last[LEN]; }; struct guy { // second structure struct names handle; // nested structure char favfood[LEN]; char job[LEN]; float income; }; int main(void) { struct guy fellow = { { "A", "B" },"sushi","coder",12345.00}; printf("Dear %s, \n\n", fellow.handle.first); printf("%s%s.\n", msgs[0], fellow.handle.first); printf("%s%s\n", msgs[1], fellow.job); printf("%s\n", msgs[2]); printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]); if (fellow.income > 150000.0) puts("!!"); else if (fellow.income > 75000.0) puts("!"); else puts("."); printf("\n%40s%s\n", " ", "See you soon,"); printf("%40s%s\n", " ", "Shalala"); return 0; }