Advertisement
pbin_

labile

Dec 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N 20
  6.  
  7. struct data{
  8.  
  9. int anno;
  10. int mese;
  11. int giorno;
  12.  
  13. };
  14.  
  15.  
  16. int main(){
  17.  
  18. FILE *ft, *fb;
  19. char name1[N];
  20. char name2[N];
  21. char testo[100];
  22.  
  23. struct data el;
  24.  
  25.  
  26. printf("\n\nInserire il nome del file testuale:");
  27. gets(name1);
  28.  
  29. printf("\n\nInserire il nome del file binario:");
  30. gets(name2);
  31.  
  32. ft=fopen(name1,"a");
  33. fb=fopen(name2,"ab");
  34.  
  35. printf("\n\nInserire il testo da scrivere nel file di testo(max.100 caratteri):");
  36. gets(testo);
  37.  
  38. printf("\n\nInserire i dati per la struct data da inserire nel file binario:");
  39.  
  40. printf("\n\nAnno:");
  41. scanf("%d", &el.anno);
  42.  
  43. printf("\n\nMese:");
  44. scanf("%d", &el.mese);
  45.  
  46. printf("\n\nGiorno:");
  47. scanf("%d",&el.giorno);
  48.  
  49. fprintf(ft, "%s", testo);
  50.  
  51. fwrite(&el, 1, sizeof(struct data), fb);
  52.  
  53. fclose(ft);
  54. fclose(fb);
  55.  
  56. ft=fopen(name1,"r");
  57. fb=fopen(name2,"rb");
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement