Advertisement
Algabe

Agenda

Jun 10th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #define DATA "Agenda"
  3.  
  4. struct Nombre{
  5.   char Nom[20];
  6.   char Ap1[20];
  7.   char Ap2[20];
  8.   char Tel[15];
  9. };
  10.  
  11. void insertarNombre(struct Nombre *n);
  12. void __fpurge(FILE *stream);
  13.  
  14. int main(){
  15.   FILE *f;
  16.   char c;
  17.   short int cont = 0;
  18.   struct Nombre n;
  19.  
  20.   insertarNombre(&n);
  21.  
  22.   f = fopen(DATA,"a+");
  23.   fprintf(f,"%s %s %s %s\n",n.Nom,n.Ap1,n.Ap2,n.Tel);
  24.   rewind(f);
  25.   while((c = fgetc(f)) != EOF){
  26.     if(c == '\n'){
  27.       cont++;
  28.     }
  29.   }
  30.   fclose(f);
  31.   fprintf(stdout,"\nNº de contactos: %d\n",cont);
  32.  
  33.   return 0;
  34. }
  35.  
  36. void insertarNombre(struct Nombre *n){
  37.   fprintf(stdout,"Nombre: ");
  38.   __fpurge(stdin);
  39.   scanf("%s",n->Nom);
  40.   fprintf(stdout,"Apellido 1: ");
  41.   __fpurge(stdin);
  42.   scanf("%s",n->Ap1);
  43.   fprintf(stdout,"Apellido 2: ");
  44.   __fpurge(stdin);
  45.   scanf("%s",n->Ap2);
  46.   fprintf(stdout,"Teléfono: ");
  47.   __fpurge(stdin);
  48.   scanf("%s",n->Tel);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement