SHARE
TWEET

Untitled

a guest Mar 15th, 2018 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <search.h>
  5.  
  6. struct critter{
  7.         char name[30];
  8.         char specias[30];
  9.         int age;
  10.     };
  11.  
  12. void find_critter(const char *name)
  13. {
  14.     struct critter target, *result;
  15.     srcpy(taget.name,name);
  16.     result = (struct critter *)
  17.         bsearch(&target,muppets,count,sizeof(struct critter),schoen_critter_comp);
  18.     if(result!=NULL)
  19.     {
  20.         printf_critter(result);
  21.     }
  22.     else
  23.     {
  24.         printf("(Couldn't find %s\n",name);
  25.     }
  26. }
  27. int schoen_critter_comp(const void *c1,const void *c2)
  28. {
  29.     return strcmp(((const struct critter*)c1)->name,
  30.         ((const struct critter*)c2)->name);
  31. }
  32.        
  33.  
  34.  
  35. int main()
  36. {
  37.     struct critter muppets[]={
  38.         {"Remit","frog",5},
  39.         {"Piggy","pig",20},
  40.         {"Gonzo","whatever",33},
  41.     };
  42.     //Nur mit statisches Array
  43.     int count = sizeof(muppets)/sizeof(critter);
  44.    
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top