This repository has been archived on 2025-12-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-09-20 14:17:13 +03:00

36 lines
785 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct person {
char name[30];
int age;
} PERSON;
PERSON *queryData() {
PERSON *pPerson;
// Dynamic memory allocation
if ((pPerson = (PERSON*)malloc(sizeof(PERSON))) == NULL ){
printf("Memory allocation failed");
exit(1);
}
// Asking the information
printf("What is your name?\n");
scanf("%s", pPerson->name);
printf("What is you age?\n");
scanf("%d", &pPerson->age);
return pPerson; // return the address to the caller
}
int main(void) {
PERSON *ptr;
// collect the data
ptr = queryData();
printf("Your name is '%s' and your age is %d.\n", ptr->name, ptr->age);
free(ptr); // free the used memore in the end
return(0);
}