//homogeneous structure #include<stdio.h> typedef struct Person { char name[100]; int age_in_years; float height_in_cm; float weight_in_kg; // The pointers have to be of a specific struct type", i.e. the struct name struct Person *mother; struct Person *father; struct Person *bff; } Person; main() { Person mom = {"Emma", 40}; Person dad = {"Silverio", 45}; Person bff = {"Lily", 19}; Person son = {"Hue", 19}; son.mother = &mom; son.father = &dad; son.bff = &bff; Person maternal_grandmother = {"Calanday", 90}; Person maternal_grandfather = {"Melicio", 90}; Person paternal_grandmother = {"Amada", 90}; Person paternal_grandfather = {"Manila", 90}; son.mother->mother = &maternal_grandmother; son.mother->father = &maternal_grandfather; son.father->mother = &paternal_grandmother; son.father->father = &paternal_grandfather; // To access pointer variables within a struct data typed variable, the -> operator is used. printf("Hi, my name is %s. My mother is %s. My father is %s. My BFF is %s.\n", son.name, son.mother->name, son.father->name, son.bff->name); printf("My grandmothers are %s and %s. ", son.mother->mother->name, son.father->mother->name); printf("My grandfathers are %s and %s.", son.mother->father->name, son.father->father->name); }
Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts
Thursday, April 3, 2014
Homo Struct in C
This time I used Syntax Highlighter in posting the code. I still can't decide which is better this or Github. Just check this out for pros and cons. Apparently, SH wins over GH.
Wednesday, April 2, 2014
File IO Using Main Arguments
First, compile the code.
Using the command prompt, the first argument is the file name.
While the second argument is the name of the output file you want.
You may also specify the destination path of the file output on the second argument.
Subscribe to:
Posts (Atom)