-
Notifications
You must be signed in to change notification settings - Fork 5
/
contact_list.c
47 lines (39 loc) · 1013 Bytes
/
contact_list.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char NAME[100];
typedef char EMAIL[100];
typedef struct {
NAME name;
EMAIL email;
} CONTACT;
int main( int argc, const char * argv[] )
{
CONTACT * list = NULL;
char buffer[100];
int goOn, listSize = 0;
do {
printf( "Ingrese el nombre del nuevo contacto (0 para terminar): ");
scanf( "%99s", buffer );
if ( ( goOn = strcmp( "0", buffer ) ) ) {
if ( !list ) {
list = malloc( sizeof( CONTACT ) );
} else {
list = realloc( list, sizeof( CONTACT ) * ( listSize + 1 ) );
}
strcpy( list[ listSize ].name, buffer );
printf( "Ingrese el email de %s: ", buffer );
scanf( "%99s", buffer );
strcpy( list[ listSize ].email, buffer );
listSize++;
}
} while ( goOn );
printf( "\nEsta es tu lista de contactos:\n" );
printf("Nombre\t\tEmail\n");
printf("------\t\t-----\n");
for ( int i = 0; i < listSize; i++ ) {
printf( "%s\t\t%s\n", list[i].name, list[i].email );
}
free( list );
return 0;
}