Last active
May 30, 2018 13:42
-
-
Save not7cd/2dff5699c9ba1139a87459cdfa2c5793 to your computer and use it in GitHub Desktop.
This file contains 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> | |
struct person { | |
char given_name[20]; | |
char surname[20]; | |
unsigned int age; | |
long unsigned pesel; | |
}; | |
void print_person(struct person * ptr) { | |
printf("Name: %s %s\n", ptr - > given_name, ptr - > surname); | |
printf("Age: %i\n", ptr - > age); | |
printf("PESEL number: %lu\n", ptr - > pesel); | |
} | |
void read_person(struct person * ptr) { | |
scanf("%s", ptr - > given_name); | |
scanf("%s", ptr - > surname); | |
scanf("%i", & ptr - > age); | |
scanf("%i", & ptr - > pesel); | |
} | |
struct person * find_person(struct person * ppl, int ppl_len, char * surname) { | |
int i; | |
for (i = 0; i | |
if (strcmp(ppl[i].surname, surname) == 0) | |
return &ppl[i]; | |
return NULL; | |
}; | |
int main() { | |
struct person * ppl; | |
int ppl_len; | |
scanf("%i", & ppl_len); | |
ppl = calloc(ppl_len, sizeof(struct person)); | |
int i; | |
for (i = 0; i read_person( & ppl[i]); | |
for (i = 0; i print_person( & ppl[i]); | |
printf("search by surname: \n"); char * query; scanf("%s", query); | |
struct person * result = find_person(ppl, ppl_len, query); | |
if (result != NULL) | |
print_person(result); | |
else | |
printf("not found"); | |
free(ppl); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment