Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define DATA "Agenda"
- struct Nombre{
- char Nom[20];
- char Ap1[20];
- char Ap2[20];
- char Tel[15];
- };
- void insertarNombre(struct Nombre *n);
- void __fpurge(FILE *stream);
- int main(){
- FILE *f;
- char c;
- short int cont = 0;
- struct Nombre n;
- insertarNombre(&n);
- f = fopen(DATA,"a+");
- fprintf(f,"%s %s %s %s\n",n.Nom,n.Ap1,n.Ap2,n.Tel);
- rewind(f);
- while((c = fgetc(f)) != EOF){
- if(c == '\n'){
- cont++;
- }
- }
- fclose(f);
- fprintf(stdout,"\nNº de contactos: %d\n",cont);
- return 0;
- }
- void insertarNombre(struct Nombre *n){
- fprintf(stdout,"Nombre: ");
- __fpurge(stdin);
- scanf("%s",n->Nom);
- fprintf(stdout,"Apellido 1: ");
- __fpurge(stdin);
- scanf("%s",n->Ap1);
- fprintf(stdout,"Apellido 2: ");
- __fpurge(stdin);
- scanf("%s",n->Ap2);
- fprintf(stdout,"Teléfono: ");
- __fpurge(stdin);
- scanf("%s",n->Tel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement