Пример #1
0
void print_people(List_t* list) {
    printf("--> ID: %d, Name: %s\n", list->p->id, list->p->name);

    if (list->next) {
        print_people(list->next);
    }
}
Пример #2
0
int main() {

    List_t* l1 = (List_t*) malloc(sizeof(List_t));
    l1->p = (Person_t*) malloc(sizeof(Person_t));
    l1->p->id = 111;
    l1->p->name = "ほげほげ";
    l1->next = NULL;

    List_t* l2 = (List_t*) malloc(sizeof(List_t));
    l2->p = (Person_t*) malloc(sizeof(Person_t));
    l2->p->id = 222;
    l2->p->name = "ふがふが";
    l2->next = NULL;
    l1->next = l2;

    List_t* l3 = (List_t*) malloc(sizeof(List_t));
    l3->p = (Person_t*) malloc(sizeof(Person_t));
    l3->p->id = 333;
    l3->p->name = "ほげふが";
    l3->next = NULL;
    l2->next = l3;

    print_people(l1);
    free_people(l1);

    return 0;
}
Пример #3
0
int main(void)
{
	struct person people[SIZE];
	struct person *p[SIZE];
	int count = 0;

	printf("Enter the first name (empty line to quit): ");
	while (getstr(people[count].fname, LEN) != NULL &&
			count < MAX && people[count].fname[0] != '\0') {
		printf("Enter the middle name: ");
		getstr(people[count].mname, LEN);
		printf("Enter the last name: ");
		getstr(people[count].lname, LEN);
		printf("Enter a social security number: ");
		getstr(people[count].soc_sec_num, MAX);

		if (count < MAX)
			printf("Enter the next first name: ");
		p[count] = &people[count];
		count++;
	}

	if (count > 0) {
		puts("Printing out all the people:");
		print_people(p, count);
	}

	return 0;
}