sono riuscita a fare la prima funzione, ma la seconda non so come iniziare. qualcuno mi puo aiutare???
codice:
/*COMPITO 10 SETTEMBRE 2012*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FLUSH while(getchar()!='\n')
/*****tipobaseList*******/
#define STR 20
typedef struct{
char cognome[STR], nome[STR];
}tipobaseList;
int Confronta(tipobaseList a, tipobaseList b){
if(!strcmp(a.cognome,b.cognome))
return(strcmp(a.nome, b.nome));
else return(strcmp(a.cognome, b.cognome));
}
void LeggiStringa(char s[], unsigned int dim){
unsigned int i=0;
for(i=0; i<dim-1 && (s[i]=getchar())!='\n';i++) s[i]='\0';
if(i==dim-1) while(getchar()!='\n');
}
/********list*************/
#define LISTAVUOTA NULL
typedef struct nodoList{
tipobaseList info;
struct nodoList *next;
} *list;
typedef short boolean;
typedef list position;
void MakeNullList(list *l){
*l==LISTAVUOTA;
}
boolean EmptyList(list l){
return(l==LISTAVUOTA);
}
boolean FullList(list l){
return(0);
}
position End(list l){
if(l==LISTAVUOTA) return(LISTAVUOTA);
while(l->next!=LISTAVUOTA) l=l->next;
return(l);
}
position First(list l){
return(LISTAVUOTA);
}
void InsertList(list *l, position p,tipobaseList x){
struct nodoList *tmp;
if(!FullList(*l)){
tmp=(struct nodoList *) malloc(sizeof(struct nodoList));
tmp->info=x;
if(p==LISTAVUOTA){
tmp->next=*l;
*l=tmp;
}else{
tmp->next=p->next;
p->next=tmp;
}
}
}
void DeleteList(list *l, position p){
struct nodoList *tmp;
if(p==LISTAVUOTA){
tmp=(*l)->next;
free(*l);
*l=tmp;
}else {
tmp=p->next;
p->next=tmp->next;
free(tmp);
}
}
position Next(list l, position p){
if(p==LISTAVUOTA) return(l);
else return(p->next);
}
tipobaseList Retrieve(list l, position p){
if(l==LISTAVUOTA) return(l->info);
else return(l->next->info);
}
position Locate(list l, tipobaseList x){
if(!EmptyList(l)){
if(!Confronta(l->info,x)) return(LISTAVUOTA);
while(l->next!=LISTAVUOTA){
if(!Confronta(l->next->info,x)) return(l);
l=l->next;
} return(l);
}
}
/*****archivio*******/
typedef struct{
unsigned int posti_disponibili;
list posti_acquistati;
list posti_prenotati;
}archivio;
archivio *archivio_voli;
void AllocaVettore(archivio *, unsigned int);
main (){
unsigned int n, scelta;
do{
printf("\n/**********ARCHIVIO VOLI***************/");
printf("\n1-Alloca Vettore");
printf("\n2-Numero posti disponibili");
printf("\n3-Prenotazione/Acquisto volo");
printf("\n4-Conferma acquisto");
printf("\n5-Esci");
printf("\nscelta--------------->");
scanf("%u", &scelta);
switch(scelta){
case 1:
do{ printf("\nInserisci il numero di elementi del vettore: ");
scanf("%u",&n);
FLUSH;
}while(n<2);
AllocaVettore(archivio_voli, n);
break;
case 2:
}
}while(scelta<4);
}
void AllocaVettore(archivio *x, unsigned int n){
x=(archivio *)malloc(n*sizeof(archivio));
}