Advertisement
mouhsineelachbi

Phone Challenge

Aug 9th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef struct phone
  5. {
  6.     char nom[100];
  7.     int num;
  8. }phone;
  9.  
  10. int main()
  11. {
  12.     phone *t,*p,*q;
  13.     int n,i,k,j,c;
  14.     char name[100];
  15.    
  16.     printf("Saisir N :\n");
  17.     t=(phone*)malloc(n*sizeof(phone));
  18.     scanf("%d",&n);
  19.     j=n;
  20.     q=t;
  21.     i=0;
  22.     while(j)
  23.     {
  24.         printf("Saisir le nom et le numero : \n");
  25.         scanf("%s %d",q->nom,&t[i].num);
  26.         q++;
  27.         i++;
  28.         j--;
  29.     }
  30.     for(j=0,c=0;j<n;j++)
  31.     {
  32.         printf("Saisir un nom a chercher : ");
  33.         scanf("%s",name);printf("\n");
  34.         for(p=t;p<t+n;p++)
  35.         {
  36.             if(strcmp(p->nom,name)==0)
  37.             {
  38.                 printf("%s=%d",p->nom,p->num);c=1;break;
  39.             }
  40.             else
  41.                 c=0;
  42.         }
  43.         if(c==0)
  44.             printf("Not found\n");
  45.     }
  46. system("pause");
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement