-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponsavel.c
111 lines (94 loc) · 2.72 KB
/
responsavel.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "responsavel.h"
#include "crianca.h"
void adicionar_responsavel(char nome[80], int telefone, Responsavel **responsavel)
{
Responsavel *resp = (Responsavel*)malloc(sizeof(Responsavel));
strcpy(resp->nome, nome);
resp->telefone = telefone;
resp->proximo = NULL;
resp->crianca = NULL;
if (*responsavel == NULL)
{
*responsavel = resp;
}
else
{
Responsavel *ultimo;
for (ultimo = *responsavel; ultimo->proximo != NULL; ultimo = ultimo->proximo);
ultimo->proximo = resp;
}
}
Responsavel *busca_crianca_nas_lst(Responsavel *r, char nome[100]){
Responsavel *ref;
Crianca *p;
for(ref = r; ref != NULL; ref = ref->proximo){
for(p = ref->crianca; p != NULL; p = p->proximo){
if(strcmp(p->nome, nome) == 0){
return ref;
}
}
}
return NULL;
}
void excluir_responsavel(Responsavel **responsavel, char nome[80])
{
if (*responsavel == NULL)
{
return;
}
else
{
Responsavel *anterior = NULL;
Responsavel *pont;
for (pont = *responsavel; pont != NULL; pont = pont->proximo)
{
if (strcmp(nome, pont->nome) == 0)
{
if (anterior == NULL)
{
Responsavel *temp;
temp = pont;
*responsavel = temp->proximo;
free(temp);
}
else
{
Responsavel *temp;
temp = pont;
anterior->proximo = temp->proximo;
free(temp);
}
}
anterior = pont;
}
}
}
void listar_responsavel_e_criancas(Responsavel *responsavel)
{
Responsavel *pont1;
Crianca *pont2;
for (pont1 = responsavel; pont1 != NULL; pont1 = pont1->proximo)
{
printf("Nome: %s\t", pont1->nome);
printf("Numero: %d\n", pont1->telefone);
for (pont2 = pont1->crianca; pont2 != NULL; pont2 = pont2->proximo)
{
printf("Nome: %s\t", pont2->nome);
printf("Documento: %d\t", pont2->doc);
printf("Sexo: %s\t", pont2->sexo);
printf("Idade: %d\n", pont2->idade);
}
}
}
Responsavel *busca_responsavel(Responsavel *r, char nome[80]){
Responsavel *p;
for(p = r; p != NULL; p = p->proximo){
if(strcmp(p->nome, nome) == 0){
return p;
}
}
return NULL;
}