Sams Teach Yourself C in 21 Days

(singke) #1

Summary ............................................................................................................


Today’s lesson showed the various ways you use C to manipulate strings. Using C stan-
dard library functions (and possibly some non-ANSI, compiler-specific functions as
well), you can copy, concatenate, compare, and search strings. These are all necessary
tasks in most programming projects. The standard library also contains functions for con-
verting the case of characters in strings and for converting strings to numbers. Finally, C
provides a variety of character-test functions or, more accurately, macros that perform a
variety of tests on individual characters. By using these macros to test characters, you
can create your own custom input functions.

Q&A ....................................................................................................................


Q How do I know whether a function is ANSI compatible?
AMost compilers have a Library Function Reference manual or section. This manual
or section of a manual lists all the compiler’s library functions and how to use
them. Usually, the manual includes information on the compatibility of the func-
tion. Sometimes, the descriptions state not only whether the function is ANSI-com-
patible, but also whether it is compatible with DOS, UNIX, Windows, C++, or
OS/2. (Most compilers tell you only what is relevant to their compiler.)
Q Are all the available string functions presented in today’s lessons?
ANo. However, the string functions presented today should cover virtually all your
needs. Consult your compiler’s Library Reference to see what other functions are
available.
Q Doesstrcat()ignore trailing spaces when doing a concatenation?
ANo.strcat()looks at a space as just another character.
Q Can I convert numbers to strings?
AYes. You can write a function similar to the one in Listing 17.16, or you can check
your Library Reference for available functions. Some functions available include
itoa(),ltoa(),andultoa().sprint(f)can also be used.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned.

512 Day 17

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

Free download pdf