1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARR_SIZE 7
char* names[ARR_SIZE]= {"Simon", "Suzie", "Alfred", "Chip", "John", "Tim", "Harriet"};
int ages[ARR_SIZE]= {22, 24, 106, 6, 18, 32, 24};
typedef struct {
char* name;
int age;
} person;
static void insert(person*, char*, int);
int main(int argc, char* argv[]) {
person* people = (person*) malloc(ARR_SIZE * sizeof(person));
for (int i = 0; i < ARR_SIZE; ++i) {
insert(&people[i], names[i], ages[i]);
}
for (int i = 0; i < ARR_SIZE; ++i) {
printf("Person #%d: (Name: %s; Age: %d)\n", i + 1, people->name, people->age);
}
return 0;
}
static void insert(person* next, char* name, int age) {
next->name = name;
next->age = age;
}
| |