home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rpos2101.zip / RSTRING.C < prev    next >
C/C++ Source or Header  |  1998-07-02  |  2KB  |  84 lines

  1. /*
  2.  * rstring.c
  3.  * This file implements some of Turbo/Borland C++'s string functions
  4.  * written by Rob Linwood (auntfloyd@biosys.net)
  5.  * Define the macro STANDALONE to get a small, standalone test program
  6.  */
  7.  
  8.    /**********************************************************************
  9.     RPilot: Rob's PILOT Interpreter
  10.     Copyright 1998 Rob Linwood
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software
  24.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.     **********************************************************************/
  26.  
  27.  
  28. #include <ctype.h>
  29.  
  30. #ifdef STANDALONE
  31. char *strupr( char *s );
  32. char *strset( char *s, int ch );
  33.  
  34. void main()
  35. {
  36.     char text[10] = "Hello!";
  37.  
  38.     printf( "strupr( \"Dilbert\" ) = %s\n", strupr( "Dilbert" ) );
  39.     printf( "strset( text, 'C' ) = %s\n", strset( text, 'C' ) );
  40. }
  41.  
  42. #endif  /* ifdef STANDALONE */
  43.  
  44. /*
  45.  * Name    : strupr
  46.  * Descrip : Changes s to all uppercase
  47.  * Input   : s = pointer to a string to uppercase
  48.  * Output  : returns a pointer to s
  49.  * Notes   : none
  50.  * Example : strupr( "proper-noun" ) - returns "PROPER-NOUN"
  51.  */
  52.  
  53. char *strupr( char *s )
  54. {
  55.     unsigned char c;
  56.  
  57.     for(c=0; s[c] != 0; c++)
  58.         s[c] = toupper(s[c]);
  59.  
  60.     return s;
  61. }
  62.  
  63. /*
  64.  * Name    : strset
  65.  * Descrip : Sets all characters in s to ch
  66.  * Input   : s = pointer to a string to set
  67.  *           ch = character to set all positions in s to 
  68.  * Output  : returns a pointer to s
  69.  * Notes   : None
  70.  * Example : char cstring[10];
  71.              strset( cstring, 'C' ) - returns "CCCCCCCCC"
  72.  */
  73.  
  74. char *strset( char *s, int ch )
  75. {
  76.     unsigned char c;
  77.  
  78.     for(c=0; s[c] != 0; c++)
  79.         s[c] = ch;
  80.  
  81.     return s;
  82. }
  83.  
  84.