ciusss89
27-05-2010, 15:48
Salve,
Ho un problema nella definizione della struttura dati. Vorrei fare una lista di liste.
Tale necessità è dattata dalla sistuzione seguente:
ho un file che contiene un numero indefinito di paziente, sul quale su ogni riga è riportato paziente è temperatura.
Esempio del file in ingresso.
1 36.3 ROSSI
1 36.6 BIANCHI
2 37.1 ROSSI
3 36.1 BIANCHI
4 39.2 ROSSI
5 34.1 ROSSI
HO pensato la struttura dati cosi:
Una lista principale che contiene soldanto i nomi dei pazienti (in questo caso solo 2), e una lista secondaria che dipenda dalla prima, la quale contiene per ogni pazienete la serie delle temperatura lette sullo stesso paziente.
per accedere alla seconda lista intendo seguire qualcosa tipo:
pntA->pntB->campo
Vorrei chiarimenti su come definere le strutture. grazie
Il mio sviluppato per il momento:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define L_nome 20+1
#define db 1
// Gestione acquisizione dati CAMPI di CC.DAT [Giorno rilevazione] [Temp paziente] [Nome]
// Lista secondaria contenente le "misurazioni sui pazienti" sui pazienti.
struct newT{
int day;
float temperature;
struct newT *nextT;
};
// Lista principale contenente la lista pazienti.
struct newP{
int **T;
char paziente[L_nome];
struct newP *nextP;
};
//*****************MAIN FUNCTIONS*****************
struct newP* scanDATA(struct newP *, FILE*);
struct newP* buildP();
struct newT* buildT();
struct newP* Move(struct newP *, char *);
struct newP* Wiev_list(struct newP *);
//*************AND OF MAIN FUNCTIONS**************
int main (){
//**********************VAR**********************
FILE *fin1;
struct newP *ptopP;
ptopP=NULL;
//*******************END OF VAR******************
if((fin1=fopen("cc.dat","r"))==NULL){
fprintf(stderr,"\nERROR!: I can't open your file ");
exit(EXIT_FAILURE);
}
ptopP=scanDATA(ptopP,fin1);
return 0;
}
//**************Details of Funcitions****************
struct newP* scanDATA(struct newP *ptopP, FILE* dati){
//**debug
if(db==1)
printf("\n-----------FUNZIONE scanDATA-----------\n");
int Day;
float Temp;
char Nome[L_nome];
while (fscanf(dati,"%d %f %s",&Day,&Temp,Nome)!=EOF){
//**debug
if(db==1)
printf("%d %f %s \n",Day,Temp,Nome);
ptopP=Move(ptopP,Nome);
}
if(db==1)
Wiev_list(ptopP);
//**debug
if(db==1)
printf("\n-----------END OF scanDATA-------------");
return (ptopP);
}
struct newP* buildP(){
struct newP *newPTR;
newPTR=(struct newP*)malloc(sizeof (struct newP));
if(newPTR==NULL){
fprintf(stderr,"Memory denied");
exit(EXIT_FAILURE);
}
return(newPTR);
}
struct newT* buildT(){
struct newT *newPTR;
newPTR=(struct newT*)malloc(sizeof (struct newT));
if(newPTR==NULL){
fprintf(stderr,"Memory denied");
exit(EXIT_FAILURE);
}
return(newPTR);
}
struct newP* Move(struct newP *ptopP, char *PAZIENTE){
int add=1;
struct newP *ptmpSERCH;
struct newP *ptmp;
ptmpSERCH=ptopP;
//CHECK!
while(ptmpSERCH!=NULL){
if(strcmp(PAZIENTE,ptmpSERCH->paziente)==0)
add=0;
ptmpSERCH=ptmpSERCH->nextP;
}
//NUOVO paziente
if(add==1){
ptmp=buildP();
strcpy(ptmp->paziente,PAZIENTE);
ptmp->nextP=ptopP;
add=1;
ptopP=ptmp;
}
//Dati per paziente?
return (ptopP);
}
struct newP* Wiev_list(struct newP *punt){
printf("\nLista pazienti della lista:");
while(punt!=NULL){
printf("\n%s",punt->paziente);
punt=punt->nextP;
}
}
Ho un problema nella definizione della struttura dati. Vorrei fare una lista di liste.
Tale necessità è dattata dalla sistuzione seguente:
ho un file che contiene un numero indefinito di paziente, sul quale su ogni riga è riportato paziente è temperatura.
Esempio del file in ingresso.
1 36.3 ROSSI
1 36.6 BIANCHI
2 37.1 ROSSI
3 36.1 BIANCHI
4 39.2 ROSSI
5 34.1 ROSSI
HO pensato la struttura dati cosi:
Una lista principale che contiene soldanto i nomi dei pazienti (in questo caso solo 2), e una lista secondaria che dipenda dalla prima, la quale contiene per ogni pazienete la serie delle temperatura lette sullo stesso paziente.
per accedere alla seconda lista intendo seguire qualcosa tipo:
pntA->pntB->campo
Vorrei chiarimenti su come definere le strutture. grazie
Il mio sviluppato per il momento:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define L_nome 20+1
#define db 1
// Gestione acquisizione dati CAMPI di CC.DAT [Giorno rilevazione] [Temp paziente] [Nome]
// Lista secondaria contenente le "misurazioni sui pazienti" sui pazienti.
struct newT{
int day;
float temperature;
struct newT *nextT;
};
// Lista principale contenente la lista pazienti.
struct newP{
int **T;
char paziente[L_nome];
struct newP *nextP;
};
//*****************MAIN FUNCTIONS*****************
struct newP* scanDATA(struct newP *, FILE*);
struct newP* buildP();
struct newT* buildT();
struct newP* Move(struct newP *, char *);
struct newP* Wiev_list(struct newP *);
//*************AND OF MAIN FUNCTIONS**************
int main (){
//**********************VAR**********************
FILE *fin1;
struct newP *ptopP;
ptopP=NULL;
//*******************END OF VAR******************
if((fin1=fopen("cc.dat","r"))==NULL){
fprintf(stderr,"\nERROR!: I can't open your file ");
exit(EXIT_FAILURE);
}
ptopP=scanDATA(ptopP,fin1);
return 0;
}
//**************Details of Funcitions****************
struct newP* scanDATA(struct newP *ptopP, FILE* dati){
//**debug
if(db==1)
printf("\n-----------FUNZIONE scanDATA-----------\n");
int Day;
float Temp;
char Nome[L_nome];
while (fscanf(dati,"%d %f %s",&Day,&Temp,Nome)!=EOF){
//**debug
if(db==1)
printf("%d %f %s \n",Day,Temp,Nome);
ptopP=Move(ptopP,Nome);
}
if(db==1)
Wiev_list(ptopP);
//**debug
if(db==1)
printf("\n-----------END OF scanDATA-------------");
return (ptopP);
}
struct newP* buildP(){
struct newP *newPTR;
newPTR=(struct newP*)malloc(sizeof (struct newP));
if(newPTR==NULL){
fprintf(stderr,"Memory denied");
exit(EXIT_FAILURE);
}
return(newPTR);
}
struct newT* buildT(){
struct newT *newPTR;
newPTR=(struct newT*)malloc(sizeof (struct newT));
if(newPTR==NULL){
fprintf(stderr,"Memory denied");
exit(EXIT_FAILURE);
}
return(newPTR);
}
struct newP* Move(struct newP *ptopP, char *PAZIENTE){
int add=1;
struct newP *ptmpSERCH;
struct newP *ptmp;
ptmpSERCH=ptopP;
//CHECK!
while(ptmpSERCH!=NULL){
if(strcmp(PAZIENTE,ptmpSERCH->paziente)==0)
add=0;
ptmpSERCH=ptmpSERCH->nextP;
}
//NUOVO paziente
if(add==1){
ptmp=buildP();
strcpy(ptmp->paziente,PAZIENTE);
ptmp->nextP=ptopP;
add=1;
ptopP=ptmp;
}
//Dati per paziente?
return (ptopP);
}
struct newP* Wiev_list(struct newP *punt){
printf("\nLista pazienti della lista:");
while(punt!=NULL){
printf("\n%s",punt->paziente);
punt=punt->nextP;
}
}