Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.c
- #include <stdio.h>
- #include "logic.h"
- #define MAX 20
- int main()
- {
- paziente registro[MAX]={0};
- int temp;
- int cursore=0;//primo elemento libero dell'array
- data date_temp;
- while(1)
- {
- printf("1.Inserire nuovi dati\n");
- printf("2.Ricerca per data di ricovero\n");
- scanf("%d", &temp);
- switch(temp)
- {
- case 1: insert(registro, &cursore);
- break;
- case 2: printf("Inserire la data di ricovero (GG/MM/AAAA)\n");
- scanf("%d/%d/%d", &date_temp.giorno, &date_temp.mese, &date_temp.anno);
- temp=search(date_temp,registro, &cursore);
- if (temp!=-1)
- printf("Nome: %c\nData di nascita: %d/%d/%d\nGenere: %c\nDisturbo: %c",registro[temp].nome, registro[temp].nascita.giorno, registro[temp].nascita.mese, registro[temp].nascita.anno, registro[temp].genere, registro[temp].malattia);
- else printf("Non รจ stata trovata nessuna corrispondenza\n");
- break;
- default: return 0;
- break;
- }
- }
- return 0;
- }
- //end_main.c
- //logic.c
- #include <stdio.h>
- #include "logic.h"
- void insert(paziente *registro, int* cursore)
- {
- printf("Inserire il nome del paziente:\n");
- scanf(" %c", ®istro[*cursore].nome);
- printf("Inserire la data di nascita GG/MM/AAAA:\n");
- scanf(" %d/%d/%d", ®istro[*cursore].nascita.giorno,®istro[*cursore].nascita.mese,®istro[*cursore].nascita.anno);
- printf("Inserire il genere (M/F):\n");
- scanf(" %c", ®istro[*cursore].genere);
- printf("Inserire la data di ricovero:\n");
- scanf(" %d/%d/%d", ®istro[*cursore].ricovero.giorno,®istro[*cursore].ricovero.mese,®istro[*cursore].ricovero.anno);
- printf("Inserire il disturbo del paziente:\n");
- scanf(" %c", ®istro[*cursore].malattia);
- *cursore++;
- printf("Inserimento completato.\n");
- }
- int search(data date_temp, paziente *registro, int *cursore)
- {
- paziente res;
- int i=0;
- int found=1;
- while((i<*cursore) && (found!=0))
- {
- if ((registro[i].ricovero.giorno==date_temp.giorno) && (registro[i].ricovero.mese==date_temp.mese) && (registro[i].ricovero.anno==date_temp.anno))
- {
- found=0;
- break;
- }
- i++;
- }
- if (found==0) return i;
- else return -1;
- }
- //end_logic.c
- //logic.h
- #ifndef LOGIC_H
- #define LOGIC_H
- typedef struct tipo_data
- {
- unsigned int giorno;
- unsigned int mese;
- unsigned int anno;
- } data;
- typedef struct informazioni
- {
- char nome;
- data nascita;
- char genere;
- data ricovero;
- char malattia;
- } paziente;
- void insert(paziente *registro, int* cursore);
- int search(data date_temp, paziente *registro, int *cursore);
- #endif
- //end_logic.h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement