2 * sestaveni: gcc tel.c -o tel; nebo: make tel;
16 ll
*list
= (ll
*) malloc(sizeof(ll
));
23 void ll_add(ll
*list
, void *ptr
) {
24 for(;list
->next
!= 0;list
= (ll
*) list
->next
);
25 list
->next
= (struct ll
*) ll_new();
26 list
->data
= (void *) ptr
;
29 void ll_rm(ll
**llptr
) {
31 *llptr
= (ll
*) (*llptr
)->next
;
35 void ll_walk(ll
*list
, void (*function
)(ll
*ptr
)) {
36 for(;list
->next
!= 0;list
= (ll
*) list
->next
) function(list
);
39 void ll_walk_data(ll
*list
, void (*function
)(void *ptr
)) {
40 for(;list
->next
!= 0;list
= (ll
*) list
->next
) if(list
->data
!= 0) function(list
->data
);
50 contact
*contact_new() {
51 contact
*c
= (contact
*) malloc(sizeof(contact
));
53 scanf("%15s", c
->name
);
54 if(c
->name
[0] == '.') return 0;
55 scanf("%15s", c
->sname
);
56 scanf("%15s", c
->telno
);
60 void contact_print(contact
*c
) {
61 printf("%-15s %-15s %-15s\n", c
->name
, c
->sname
, c
->telno
);
64 char contact_match(contact
*c
, char *str
) { //vrati true, kdyz kontakt odpovida
65 return !(strcmp(c
->name
, str
) && strcmp(c
->sname
, str
) && strcmp(c
->telno
, str
));
68 char contact_compare(contact
*a
, contact
*b
) { //vrati true, kdyz jsou kontakty stejne
69 return !(strcmp(a
->name
, b
->name
) || strcmp(a
->sname
, b
->sname
) || strcmp(a
->telno
, b
->telno
));
73 char find_string
[64] = "";
74 void contact_find(ll
*item
) {
75 if(contact_match(item
->data
, find_string
)) {
76 contact_print(item
->data
);
80 void contact_remove(ll
**llptr
) {
81 //bohuzel nejde pouzit contact_find + ll_walk protoze je treba mit referenci na prvni polozku pro pripad potreby jejiho odstraneni
82 while((*llptr
)->next
!= 0) {
83 if(contact_match((*llptr
)->data
, find_string
)) {
84 printf("DELETED: "); contact_print((*llptr
)->data
);
88 llptr
= (ll
**) &((*llptr
)->next
);
97 //ukazka pouziti linked-listu
101 ll_walk_data(list, puts);
103 puts("first item removed...");
104 ll_walk_data(list, puts);
108 //ukazka pouziti kontaktu
109 contact *c = contact_new();
115 "\n\tTelefonni seznam 0.1 (mudruto1)\n"
116 "Zadavejte kontakty ve formatu 'jmeno prijmeni cislo' kazdy na novou radku.\n"
117 "Po zadani posledniho kontaktu zadejte radku zacinajici teckou.\n"
119 "tomas mudrunka 123456789\n"
120 "daniel novak 987654321\n"
121 "alice obrovska 456789123\n"
125 ll
*seznam
= (ll
*) ll_new();
127 while(c
= contact_new()) ll_add(seznam
, c
);
129 "------------------------------------------\n"
130 "jmeno prijmeni cislo\n"
132 ll_walk_data(seznam
, contact_print
);
134 puts("\n\nCo hledat?");
135 scanf("%15s", find_string
);
136 ll_walk(seznam
, contact_find
);
138 puts("\nCo smazat?");
139 scanf("%15s", find_string
);
140 contact_remove(&seznam
);
142 puts("\nTakto vypada seznam bez smazane polozky:\n");
143 ll_walk_data(seznam
, contact_print
);
This page took 0.714849 seconds and 4 git commands to generate.