Created
March 14, 2022 16:55
-
-
Save webgtx/98e73c6d53d6ed940314b8a28cd66daa to your computer and use it in GitHub Desktop.
How structure works in C
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
struct author { | |
int age; | |
char uname[80]; | |
char stack[80]; | |
}; | |
struct author new_developer() { | |
struct author new; | |
printf("Username: "); | |
lnrd(new.uname); | |
printf("Stack: "); | |
lnrd(new.stack); | |
return new; | |
} | |
void lnrd(char * str) { | |
int idx = 0; | |
while (true) { | |
char ch = getchar(); | |
if (ch == '\n') | |
break; | |
str[idx] = ch; | |
idx++; | |
} | |
str[idx++] = '\0'; | |
} | |
void pgrd() { | |
struct author dev; | |
dev = new_developer(); | |
printf("Developer username: %s\n Stack: %s", dev.uname, dev.stack); | |
} | |
void stfn(struct author *dev) { | |
printf("age is %i\n", dev->age); | |
} | |
int main() { | |
struct author dev = { | |
22, | |
"Jhon", | |
"JS" | |
}, | |
*pdev = &dev; | |
printf("Username: %s\n", pdev->uname); | |
stfn(pdev); | |
// pgrd(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment