home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX02009.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  756 b   |  34 lines

  1. // ex02009.cpp
  2. // Linkage-specifications
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. // ------ prototype for a C function
  8. extern "C" int comp(const void *a, const void *b);
  9.  
  10. main()
  11. {
  12.     // --------- array of string pointers to be sorted
  13.     static char *brothers[] = {
  14.         "Frederick William",
  15.         "Joseph Jensen",
  16.         "Harry Alan",
  17.         "Walter Elsworth",
  18.         "Julian Paul"
  19.     };
  20.     // ---------- sort the pointers
  21.     qsort(brothers, 5, sizeof(char *), comp);
  22.     // ---------- display the brothers in sorted order
  23.     for (int i = 0; i < 5; i++)
  24.         cout << '\n' << brothers[i];
  25. }
  26.  
  27. // ---------- a function compiled with C linkage
  28. extern "C"    {
  29. int comp(const void *a, const void *b)
  30. {
  31.     return strcmp(*(char **)a, *(char **)b);
  32. }
  33. }
  34.