Guest User

Untitled

a guest
Jun 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef char STRING[20];
  5. typedef struct { STRING cognome;   STRING nome;
  6. int num; } UTENTE;
  7.  
  8. int main()
  9. { FILE *out;  /* dichiarazione puntatore a FILE */
  10. UTENTE rec; /*dichiarazione della struttura */
  11.  
  12. if((out=fopen("testo.txt","r"))==NULL);
  13. {printf("Errore nell'apertura del file");
  14. exit(1);}
  15.  
  16. int risposta=0;
  17. {while(risposta!=0)
  18.                  printf("Inserisci cognome:");
  19.                  scanf("%s",rec.cognome);
  20.            
  21. printf("Inserisci nome:");
  22. scanf("%s",rec.nome);
  23.  
  24. printf("Inserisci numero di telefono:");              
  25. scanf("%d",&rec.num);
  26.  
  27.  
  28. fprintf(out,"%s %s %s %d\n",rec.cognome,rec.nome,rec.num);
  29. printf("vuoi continuare?(premi 1(no) o 0(si)!");
  30. scanf("%d",&risposta);
  31. printf("\n");
  32. }
  33. fclose (out);
  34. if((out=fopen("testo.txt","r"))==NULL);
  35. {printf("Errore nell'apertura del file");
  36. exit(1);}
  37. while(!feof(out))
  38. {fscanf (out, "%s%s%d\n", &rec.cognome, &rec.nome, &rec.num);
  39.  
  40. printf ("%20s%20s%10d", rec.cognome, rec.nome, rec.num);
  41. printf ("\n");
  42. }
  43.  
  44. system("pause");
  45. return 0;
  46.          
  47. }
Add Comment
Please, Sign In to add comment