diff options
Diffstat (limited to 'c/structs.c')
| -rw-r--r-- | c/structs.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/c/structs.c b/c/structs.c new file mode 100644 index 0000000..4e8670a --- /dev/null +++ b/c/structs.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <string.h> + +struct dog { + int age; + int weight; + char color[16]; + char name[16]; +}; + + +void menu(struct dog atlas) { + int option; + + do { + printf("dawg\n"); + printf("1. Option 1\n"); + printf("2. Option 2\n"); + printf("3. Option 3\n"); + printf("4. Exit\n"); + scanf("%d", &option); + + switch (option) { + case 1: + printf("name: %s\n", atlas.name); + break; + case 2: + printf("age: %d\n", atlas.age); + break; + case 4: + printf("exiting...\n"); + break; + default: + printf("Invalid option\n"); + } + } while (option != 4); +} + +int main() { + struct dog atlas; + atlas.age = 7; + atlas.weight = 77; + strcpy(atlas.color, "black"); + strcpy(atlas.name, "atlas"); + + menu(atlas); + return 0; +} + |
