Sams Teach Yourself C in 21 Days

(singke) #1
Enter a line of text, a blank to exit.
Bradley L. Jones
bradley l. jones
BRADLEY L. JONES
Enter a line of text, a blank to exit.
This listing prompts for a string on line 12. It then checks to ensure that the
string isn’t blank (line 15). Line 18 prints the string after converting it to lower-
case. Line 19 prints the string in all uppercase.
These functions are a part of the Dev-C++, Symantec, Microsoft, and Borland C
libraries. You need to check the Library Reference for your compiler before using these
functions. If portability is a concern, you should avoid using non-ANSI functions such as
these.

Miscellaneous String Functions ..........................................................................


This section covers a few string functions that don’t fall into any other category. They all
require the header file string.h. The functions covered are


  • strrev()

  • strset()

  • strnset()


Thestrrev()Function ................................................................................


The function strrev()reverses the order of all the characters in a string. Its prototype is
char *strrev(char *str);
The order of all characters in stris reversed, with the terminating null character remain-
ing at the end. The strrev()function is not defined in the ANSI standard. As stated
before, this means that it may not be supported in all compilers, or that it may be sup-
ported differently.
The function returns str. After strset()andstrnset()are defined in the next section,
strrev()is demonstrated in Listing 17.14.

Thestrset()andstrnset()Functions ......................................................


Like the previous function,strset(), andstrnset()aren’t part of the ANSI C standard
library. These functions change all characters (strset()) or a specified number of char-
acters (strnset()) in a string to a specified character. The prototypes are

502 Day 17

INPUT/
OUTPUT

ANALYSIS

28 448201x-CH17 8/13/02 11:13 AM Page 502

Free download pdf