Created
April 24, 2013 13:02
-
-
Save TheCodeEngine/5451961 to your computer and use it in GitHub Desktop.
A struct example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char const *argv[]) | |
| { | |
| struct fish | |
| { | |
| const char *name; | |
| const char *species; | |
| int teeth; | |
| int age; | |
| }; | |
| struct fish snappy = {"Snappy", "Piranha", 69, 4}; | |
| struct fish gnasher = snappy; | |
| fprintf(stdout, "Fish Name: %s\n", snappy.name); | |
| fprintf(stdout, "Fish Species: %s\n", snappy.species); | |
| fprintf(stderr, "Fish Age: %d\n", snappy.age); | |
| /* The same with typedef */ | |
| typedef struct cell_phone | |
| { | |
| int number; | |
| } phone; | |
| phone p = { 0151 }; | |
| fprintf(stdout, "Phone Number: %d\n", p.number); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment