Guest User

Untitled

a guest
Jan 6th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. //main.c - Ordinamento
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include "ordinamento.h"
  8.  
  9. int main(int argc,char *argv[]) {
  10.     double valore = 0;
  11.     double numero = 0;
  12.  
  13.     FILE *mfptr = NULL;
  14.     Node *head = NULL;
  15.  
  16.     if ( (mfptr = fopen(argv[1], "r") ) == NULL) {
  17.         printf ("Impossibile aprire questo file\n");
  18.     }
  19.  
  20.     else {
  21.         while (!feof (mfptr)) {
  22.             Node *el = malloc (sizeof(Node));
  23.             fscanf(mfptr,"%le\n",&valore);
  24.             el->valore = valore;
  25.             el->next = NULL;
  26.             inserisci(&head, el);
  27.         }
  28.  
  29.         printf ("Lista senza indice NON ordinata: \n");
  30.         stampa(head);
  31.         printf("\n");
  32.        
  33.         ordina (&head);
  34.         assegna_id(&head);
  35.         printf ("Lista con indice e ordinata: \n");
  36.         stampa(head);
  37.     }      
  38.    
  39.     numero = strtod (argv[2] , NULL);
  40.         fclose(mfptr);
  41.     return trova_id(&head , (int) numero);
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment