Created
May 11, 2025 08:27
-
-
Save iKunalChhabra/d3871b8b0431a03827674efac6dcb852 to your computer and use it in GitHub Desktop.
C program with coloured output and named args to struct
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> | |
| char* red = "\033[1;31m"; | |
| char* blue = "\033[1;32m"; | |
| char* green = "\033[1;34m"; | |
| char* reset = "\033[0m"; | |
| typedef enum{ | |
| MALE, | |
| FEMALE | |
| } Gender; | |
| typedef struct | |
| { | |
| char* name; | |
| int age; | |
| Gender gender; | |
| } Person; | |
| void print_person(Person* p){ | |
| const char* gender_string = (p->gender == MALE) ? "MALE" : "FEMALE"; | |
| printf("%sPerson%s%s(name=%s, age=%d, gender=%s)%s\n", | |
| blue, reset, | |
| green, | |
| p->name, p->age, gender_string, | |
| reset); | |
| } | |
| int main(){ | |
| puts(""); | |
| Person p = {.name = "Kunal", .gender = MALE, .age = 27}; | |
| print_person(&p); | |
| printf("Size of Person = %zu\n", sizeof(p)); | |
| puts(""); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment