Next: Character Set Handling, Previous: Character Handling, Up: Main Menu [Contents][Index]
Operations on strings (null-terminated byte sequences) are an important part of
many programs. The GNU C Library provides an extensive set of string
utility functions, including functions for copying, concatenating,
comparing, and searching strings. Many of these functions can also
operate on arbitrary regions of storage; for example, the
function can be used to copy the contents of any kind of array.
It’s fairly common for beginning C programmers to “reinvent the wheel” by duplicating this functionality in their own code, but it pays to become familiar with the library functions and to make use of them, since this offers benefits in maintenance, efficiency, and portability.
For instance, you could easily compare one string to another in two
lines of C code, but if you use the built-in
you’re less likely to make a mistake. And, since these library
functions are typically highly optimized, your program may run faster