Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- typedef char STRING[20];
- typedef struct { STRING cognome; STRING nome;
- int num; } UTENTE;
- int main()
- { FILE *out; /* dichiarazione puntatore a FILE */
- UTENTE rec; /*dichiarazione della struttura */
- if((out=fopen("testo.txt","r"))==NULL);
- {printf("Errore nell'apertura del file");
- exit(1);}
- int risposta=0;
- {while(risposta!=0)
- printf("Inserisci cognome:");
- scanf("%s",rec.cognome);
- printf("Inserisci nome:");
- scanf("%s",rec.nome);
- printf("Inserisci numero di telefono:");
- scanf("%d",&rec.num);
- fprintf(out,"%s %s %s %d\n",rec.cognome,rec.nome,rec.num);
- printf("vuoi continuare?(premi 1(no) o 0(si)!");
- scanf("%d",&risposta);
- printf("\n");
- }
- fclose (out);
- if((out=fopen("testo.txt","r"))==NULL);
- {printf("Errore nell'apertura del file");
- exit(1);}
- while(!feof(out))
- {fscanf (out, "%s%s%d\n", &rec.cognome, &rec.nome, &rec.num);
- printf ("%20s%20s%10d", rec.cognome, rec.nome, rec.num);
- printf ("\n");
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment