Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct studente {
- int matricola;
- char cognome[20];
- char nome[20];
- char cod_id[6];
- float media;
- struct studente *successivo;
- } studente;
- void leggi_file (FILE *input, studente **testa1);
- void change_head (studente **l1);
- void new_head (studente *l1, studente **l2, char *dato);
- void stampa (studente *testa1, FILE *output);
- int main (int argc, char **argv)
- {
- FILE *input, *output;
- studente *testa1, *testa2;
- char *dato="nappi";
- input=fopen(argv[1], "r");
- output=fopen(argv[2], "w");
- leggi_file (input, &testa1);
- new_head (testa1, &testa2, dato);
- change_head (&testa1);
- stampa (testa1, output);
- return 0;
- }
- void leggi_file(FILE * input1, studente ** testa)
- {
- studente *prec, *act;
- int matricola;
- if (fscanf(input1, "%d", &matricola)!= EOF)
- {
- prec = act = *testa = malloc(sizeof(studente));
- act->matricola = matricola;
- fscanf(input1, "%s %s %s %f", act->cognome, act->nome, act->cod_id, &act->media);
- }
- while(fscanf(input1, "%d", &matricola)!= EOF)
- {
- prec = act;
- act = malloc(sizeof(studente));
- act->matricola = matricola;
- fscanf(input1, "%s %s %s %f", act->cognome, act->nome, act->cod_id, &act->media);
- prec->successivo = act;
- }
- }
- void change_head(studente **l1)
- {
- studente *coda, *testa, *act, *prev;
- testa = act = *l1;
- while(act)
- {
- /*1*/prev = coda;
- coda = act;
- act = act->successivo;
- }
- *l1 = coda;
- /*2*/prev->successivo = NULL;
- coda->successivo = testa->successivo;
- act = *l1;
- while(act)
- {
- coda = act;
- act = act->successivo;
- }
- coda->successivo = testa;
- testa->successivo = NULL;
- }
- void new_head(studente * l1, studente **l2, char *dato)
- {
- studente * prec, *act, *to_add;
- prec = act = l1;
- while(act)
- {
- if(strcmp(act->cognome, dato) == 0)
- {
- to_add = act->successivo;
- prec = act;
- break;
- }
- prec = act;
- act = act->successivo;
- }
- prec->successivo = NULL;
- if(to_add)
- {
- *l2 = to_add;
- }
- }
- void stampa (studente *testa, FILE *output)
- {
- while(testa)
- {
- if(testa->media > 27){
- printf( "%d %s %s %s %f\n", testa->matricola, testa->cognome, testa->nome, testa->cod_id, testa->media);
- }
- testa = testa->successivo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement