Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct{
- int matricola;
- char cognome[10];
- char nome[10];
- float mediaVoti;
- }studente;
- typedef struct{
- int matricola;
- float mediaVoti;
- }newStudente;
- int update (studente *);
- int cmpRec(char **, studente);
- void copyRec(studente, newStudente **);
- void stampa (studente*, newStudente **);
- int main()
- {
- studente uno;
- newStudente *copiaUno;
- char *elenco[]={"Bianchi","Rossi","Verde"};
- if(update(&uno))
- {
- if(cmpRec(elenco,uno))
- {
- printf("Lo studente %s รจ incluso nell'elenco\n",uno.cognome);
- copyRec(uno, &copiaUno);
- stampa(&uno, &copiaUno);
- }
- else
- printf("Nessuno studente trovato, copia non effettuata\n");
- }
- else
- printf("Nessun dato inserito\n");
- return 0;
- }
- int update(studente* s)
- {
- int scelta;
- do{
- printf("Si desidera inserire un nuovo alunno? [1-si/0-no]");
- scanf("%d", &scelta);
- }while(scelta != 1 && scelta != 0);
- if(scelta)
- {
- printf("Inserisci matricola: ");
- scanf("%d", &s->matricola);
- printf("Inserisci nome: ");
- scanf("%s", s->nome);
- printf("Inserisci cognome: ");
- scanf("%s", s->cognome);
- printf("Inserisci media voti: ");
- scanf("%f", &s->mediaVoti);
- }
- return scelta;
- }
- int cmpRec(char **elenco, studente s)
- {
- int i;
- for(i=0;i<3;i++)
- {
- if(!strcmp( *(elenco + i), s.cognome))
- return 1;
- }
- return 0;
- }
- void copyRec(studente s, newStudente ** n)
- {
- (*n) = malloc(sizeof(newStudente));
- (*n)->mediaVoti = s.mediaVoti;
- (*n)->matricola = s.matricola;
- }
- void stampa (studente *s, newStudente ** n)
- {
- printf("Nome: %s, Cognome: %s, Matricola: %d, Media Voti: %f", s->nome, s->cognome, (*n)->matricola, (*n)->mediaVoti);
- }
Advertisement
Add Comment
Please, Sign In to add comment