int main(int argc, char const *argv[]) { p = (Puerto*)malloc(sizeof(Puerto)); p->tamano=5; p->cantidad=0; p->embarcaciones = (Embarcacion*)malloc(p->tamano * sizeof(Embarcacion)); agregarEmbarcacion(); agregarEmbarcacion(); agregarTripulante(); agregarTripulante(); agregarTripulante(); imprimirEmbarcaciones(); for (t=e->tripulantes; t < e->tripulantes + e->capacidad; t++) { free(t->Nombre); free(t->Apellido); free(t->Trabajo); } free(e->nombre); free(e->propietario); free(e->tripulantes); free(p->embarcaciones); free(p); return 0; }
void agregarTripulante(embarcacion * e) { int n, i, j, k; printf("\nDime cuantos tripulantes quieres agregar\n"); scanf("%d", &n); for(i = 0; i < n; ++i) { persona temp; printf("\nDime el nombre del tripulante, separa nombre apellido con enter\n"); temp.nombre = (char *) malloc(L * sizeof(char)); scanf("%s", temp.nombre); temp.apellido = (char *) malloc(L * sizeof(char)); scanf("%s", temp.apellido); printf("\nDame la edad del tripulante\n"); scanf("%d", &temp.edad); printf("\bDame el rol del tripulante\n"); temp.rol = (char *) malloc(L * sizeof(char)); scanf("%s", temp.rol); printf("\nDame el nombre de la embarcacion a que quieres asignar el tripulante\n"); imprimirEmbarcaciones(e); char *nombre = (char *) malloc(L * sizeof(char)); int igual = 1; embarcacion * ePuntero; do { scanf("%s", nombre); ePuntero = e; for(j = 0; j < barcos; ++j) { if(strcmp((*ePuntero).nombre, nombre) == 0) { if((*ePuntero).max_tripulantes > (*ePuntero).tripulantes) { igual = 0; persona * pPuntero = (*ePuntero).personas; for(k = 0; k < (*ePuntero).tripulantes; ++k) pPuntero++; *pPuntero = temp; (*ePuntero).tripulantes++; break; } else { printf("\nLa tripulacion que eligio ya esta en su cupo maximo, por favor elija otro\n"); printf("\nDesea terminar con la transaccion? Elija 1 y el tripulante sera eliminado. 0 Para continuar y buscar otro\n"); int opcion; scanf("%d", &opcion); if(opcion) { igual = 0; break; } } } ePuntero++; } if(igual) printf("\nInserte otro nombre por favor\n"); } while(igual); } }