Back to index

glibc  2.9
Classes | Functions | Variables
search.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  critter

Functions

int critter_cmp (const struct critter *c1, const struct critter *c2)
void print_critter (const struct critter *c)
void find_critter (const char *name)
int main (void)

Variables

int count = sizeof (muppets) / sizeof (struct critter)

Class Documentation

struct critter

Definition at line 7 of file search.c.

Class Members
const char * name
const char * species

Function Documentation

int critter_cmp ( const struct critter c1,
const struct critter c2 
)

Definition at line 39 of file search.c.

{
  return strcmp (c1->name, c2->name);
}

Here is the caller graph for this function:

void find_critter ( const char *  name)

Definition at line 58 of file search.c.

{
  struct critter target, *result;
  target.name = name;
  result = bsearch (&target, muppets, count, sizeof (struct critter),
                  critter_cmp);
  if (result)
    print_critter (result);
  else
    printf ("Couldn't find %s.\n", name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

Definition at line 74 of file search.c.

{
  int i;

  for (i = 0; i < count; i++)
    print_critter (&muppets[i]);
  printf ("\n");

  qsort (muppets, count, sizeof (struct critter), critter_cmp);

  for (i = 0; i < count; i++)
    print_critter (&muppets[i]);
  printf ("\n");

  find_critter ("Kermit");
  find_critter ("Gonzo");
  find_critter ("Janice");

  return 0;
}

Here is the call graph for this function:

void print_critter ( const struct critter c)

Definition at line 48 of file search.c.

{
  printf ("%s, the %s\n", c->name, c->species);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int count = sizeof (muppets) / sizeof (struct critter)

Definition at line 32 of file search.c.