diff options
author | Roland McGrath <roland@gnu.org> | 1992-05-06 05:06:34 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1992-05-06 05:06:34 +0000 |
commit | 119982076e0e2b1562bae87e5af9a0b0c61b0f99 (patch) | |
tree | 759b6e80151f8916c7899981523f88e96fbc70ab /manual/search.texi | |
parent | fbad238fa3c59a7284f3f63a10f22f39bb6074c4 (diff) |
Cleaned up code in examples.
Replaced some examples with @include foo.c.texi.
The source is found in examples/foo.c.
Diffstat (limited to 'manual/search.texi')
-rw-r--r-- | manual/search.texi | 84 |
1 files changed, 1 insertions, 83 deletions
diff --git a/manual/search.texi b/manual/search.texi index a0ec80f866..7d302429a1 100644 --- a/manual/search.texi +++ b/manual/search.texi @@ -150,89 +150,7 @@ Then, we can look up individual objects based on their names. @comment This example is dedicated to the memory of Jim Henson. RIP. @example -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -/* @r{Define an array of critters to sort.} */ - -struct critter @{ - char *name; - char *species; - @}; - -/* @r{Initialize the array, but not properly sorted.} */ - -struct critter muppets[] - = @{@{"Kermit", "frog"@}, - @{"Piggy", "pig"@}, - @{"Gonzo", "whatever"@}, - @{"Fozzie", "bear"@}, - @{"Sam", "eagle"@}, - @{"Robin", "frog"@}, - @{"Animal", "animal"@}, - @{"Camilla", "chicken"@}, - @{"Sweetums", "monster"@}, - @{"Dr. Strangepork", "pig"@}, - @{"Link Hogthrob", "pig"@}, - @{"Zoot", "human"@}, - @{"Dr. Bunsen Honeydew", "human"@}, - @{"Beaker", "human"@}, - @{"Swedish Chef", "human"@}@}; - -int count = sizeof(muppets) / sizeof(struct critter); - -/* @r{This is the comparison function for sorting and searching.} */ - -int -critter_cmp (const struct critter *c1, - const struct critter *c2) -@{ - return strcmp (c1->name, c2->name); -@} - -/* @r{Print information about a critter.} */ - -void -print_critter (const struct critter *c) -@{ - printf ("%s, the %s\n", c->name, c->species); -@} - -/* @r{Do the lookup into the sorted array.} */ - -void -find_critter (char *name) -@{ - 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); -@} - -/* @r{Main program.} */ - -void -main (void) -@{ - int i; - - 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"); -@} +@include search.c.texi @end example @cindex Kermit the frog |