September 2001
Beginner
970 pages
23h 20m
English
The C library supplies several string-handling functions; ANSI C uses the string.h header file to provide the prototypes. We'll look at some of the most useful and common ones: strlen(), strcat(), strncat(), strcmp(), strncmp(), strcpy(), and strncpy(). We'll also examine sprintf(), supported by the stdio.h header file. For a complete list of the string.h family of functions, see Reference Section V, “The ANSI C Library.”
The strlen() function, as you already know, finds the length of a string. It's used in the next example, a function that shortens lengthy strings:
/* fit.c -- procrustean function */
void fit(char * string, unsigned int size)
{
if (strlen(string) > size)
*(string + size) = '\0';
}
This ...
Read now
Unlock full access