home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / SNIP9404.ZIP / ORD_TEXT.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  665b  |  34 lines

  1. /*
  2. **  Originally published as part of the MicroFirm Function Library
  3. **
  4. **  Copyright 1991, Robert B.Stout
  5. **
  6. **  Subset version with modifications suggested by Maynard Hogg
  7. **  released to the public domain, 1992
  8. **
  9. **  Function to return ordinal text.
  10. */
  11.  
  12. static char *text[] = {"th", "st", "nd", "rd"};
  13.  
  14. char *ordinal_text(int number)
  15. {
  16.       if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
  17.             number = 0;
  18.       return text[number];
  19. }
  20.  
  21. #ifdef TEST
  22.  
  23. #include <stdio.h>
  24.  
  25. void main(void)
  26. {
  27.       int i;
  28.  
  29.       for (i = 0; i < 26; ++i)
  30.             printf("%d%s\n", i, ordinal_text(i));
  31. }
  32.  
  33. #endif /* TEST */
  34.