Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 20
- struct data{
- int anno;
- int mese;
- int giorno;
- };
- int main(){
- FILE *ft, *fb;
- char name1[N];
- char name2[N];
- char testo[100];
- struct data el;
- printf("\n\nInserire il nome del file testuale:");
- gets(name1);
- printf("\n\nInserire il nome del file binario:");
- gets(name2);
- ft=fopen(name1,"a");
- fb=fopen(name2,"ab");
- printf("\n\nInserire il testo da scrivere nel file di testo(max.100 caratteri):");
- gets(testo);
- printf("\n\nInserire i dati per la struct data da inserire nel file binario:");
- printf("\n\nAnno:");
- scanf("%d", &el.anno);
- printf("\n\nMese:");
- scanf("%d", &el.mese);
- printf("\n\nGiorno:");
- scanf("%d",&el.giorno);
- fprintf(ft, "%s", testo);
- fwrite(&el, 1, sizeof(struct data), fb);
- fclose(ft);
- fclose(fb);
- ft=fopen(name1,"r");
- fb=fopen(name2,"rb");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement