home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / ORD_TEXT.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  889b  |  42 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Originally published as part of the MicroFirm Function Library
  5. **
  6. **  Copyright 1991, Robert B.Stout
  7. **
  8. **  With modifications suggested by Maynard Hogg
  9. **
  10. **  The user is granted a free limited license to use this source file
  11. **  to create royalty-free programs, subject to the terms of the
  12. **  license restrictions specified in the LICENSE.MFL file.
  13. **
  14. **  Function to return ordinal text.
  15. */
  16.  
  17. #include "numcnvrt.h"
  18.  
  19. static char *text[] = {"th", "st", "nd", "rd"};
  20.  
  21. char *ordinal_text(int number)
  22. {
  23.       if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
  24.             number = 0;
  25.       return text[number];
  26. }
  27.  
  28. #ifdef TEST
  29.  
  30. #include <stdio.h>
  31.  
  32. main()
  33. {
  34.       int i;
  35.  
  36.       for (i = 0; i < 26; ++i)
  37.             printf("%d%s\n", i, ordinal_text(i));
  38.       return 0;
  39. }
  40.  
  41. #endif /* TEST */
  42.