Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. struct infoski infoski ;
  7. struct infoski
  8. {
  9.     char *nom;
  10.     char *adresse;
  11.     int psk;
  12. };
  13. void afficher_vec(struct infoski *skieur)
  14. {
  15.  int i;
  16.   printf("\t***************les skieurs reserves**********\n");
  17.   printf("\t+--------------------------------------------\t\n");
  18.   printf("\t NOM       | ADRESSE      | PSK      \n");
  19.   printf("\t+--------------------------------------------\t\n");
  20.  
  21.   for(i=0;i<25;i++)
  22.   {
  23.       printf("\t %s        | %s           | %d         \n",skieur[i].nom,skieur[i].adresse,skieur[i].psk);
  24.       printf("\t+-------------------------------------------\n");
  25.  
  26.   }
  27. }
  28. int cherchskieur(struct infoski *skieur,char *mot)
  29. {
  30.     int i=0;
  31.     while((skieur[i].nom)!=NULL)
  32.     {
  33.         if(strcmp(skieur[i].nom,mot)==0)
  34.         {
  35.             return(i);
  36.         }
  37.         else
  38.         {
  39.             i++;
  40.         }
  41.     }
  42.     return(-1);
  43. }
  44. int main()
  45. {
  46.    struct infoski *skieur ;
  47.    char *name=NULL;
  48.  
  49.    skieur=malloc(25 * sizeof(struct infoski));
  50.  
  51.  
  52.    printf("NOM: ");
  53.    scanf("%s",skieur[2].nom);
  54.    printf("ADRESSE: ");
  55.    scanf("%s",skieur[2].adresse);
  56.    printf("PSK: ");
  57.    scanf("%d",&skieur[2].psk);
  58.    afficher_vec(skieur);
  59.    printf("enter le nom du skieur que vous cherchez");
  60.    scanf("%s",name);
  61.    if (cherchskieur(skieur,name)!=-1)
  62.    {
  63.        printf("l'indice de skieur est: %d",cherchskieur(skieur,name) );
  64.    }
  65.  
  66.  
  67.  
  68.    return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement