Characters and Strings

Recap

Characters: the ctype library

ctype.h is a library that contains useful character handling functions. There are some conversion functions (which start with "to") and a number of query functions (which start with "is")

String declarations


String I/O:

Character and String I/O functions

These functions all come from stdio.h

The standard C string library:

The standard string library in C is called string.h.  To use it, we place the appropriate #include statement in a code file:
 #include <string.h>

This string library contains many useful string manipulation functions.  A few of the more commonly used ones are mentioned here.  (The textbook contains more detail in chapter 8)

Here is an example of the prototype of one string function:

 char* strcpy( char * s1, const char * s2 ); 

This function copies the contents of the second string (s2) into the first (s1).  Note that both parameters use Pass By Address, and the object is that two strings are passed in by name.  Since strings are character arrays, we are really passing the address of each string (char array) into the function, and not the entire string itself.  Since the addresses will be stored in the local parameters s1 and s2, the function has access to the original strings.  Note also that the second parameter is declared const -- this ensures that the string being copied is not modified by the function.  The first string must be modified, because this is where we are copying to.

The definitions of these functions are easily written with pointer and array techniques that we have already seen.
This link shows some possible ways of defining some of these functions.