agrego practicas
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#include <stdio.h>
|
||||
#include "../arena-lib/arena.h"
|
||||
#include <string.h>
|
||||
|
||||
typedef struct Persona{
|
||||
char* nombre;
|
||||
int edad;
|
||||
struct Persona* next;
|
||||
}Persona;
|
||||
|
||||
void print_persona(Persona*);
|
||||
|
||||
|
||||
int main(void){
|
||||
|
||||
printf("Alinacion struct Persona: %d\n", (int)_Alignof(Persona));
|
||||
printf("sizeof struct Persona: %d\n", (int)sizeof(Persona));
|
||||
|
||||
Arena arena = arena_create(32);
|
||||
|
||||
char continuar = 'S';
|
||||
|
||||
Persona* first = NULL;
|
||||
Persona* last = NULL;
|
||||
|
||||
do{
|
||||
char input_name[50];
|
||||
printf("Nombre:");
|
||||
if (fgets(input_name, sizeof(input_name), stdin) != NULL) {
|
||||
input_name[strcspn(input_name, "\n")] = '\0';
|
||||
}
|
||||
|
||||
int input_edad = 0;
|
||||
|
||||
printf("Edad:");
|
||||
scanf("%d", &input_edad);
|
||||
printf("\n");
|
||||
|
||||
int c;
|
||||
while ((c = getchar()) != '\n' && c != EOF);
|
||||
|
||||
Persona* p = (Persona*)arena_alloc(&arena, sizeof(Persona));
|
||||
|
||||
if(p == NULL){
|
||||
perror("Ha ocurrido un error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
p->nombre = arena_strdup(&arena, input_name);
|
||||
p->edad = input_edad;
|
||||
p->next = NULL;
|
||||
|
||||
if(first == NULL){
|
||||
first = p;
|
||||
}
|
||||
|
||||
if(last != NULL){
|
||||
last->next = p;
|
||||
}
|
||||
|
||||
last = p;
|
||||
|
||||
printf("Cargar mas personas? (S) Continuar, (N): Terminar :");
|
||||
scanf(" %c", &continuar);
|
||||
|
||||
while ((c = getchar()) != '\n' && c != EOF);
|
||||
|
||||
}while((continuar == 'S') || (continuar == 's'));
|
||||
|
||||
printf("Listado de personas cargadas:\n");
|
||||
printf("=============================\n");
|
||||
|
||||
Persona* current = first;
|
||||
while(current != NULL){
|
||||
print_persona(current);
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
arena_free(&arena);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_persona(Persona* ref_persona) {
|
||||
printf("%s: tiene %d years\n", ref_persona->nombre, ref_persona->edad);
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user