September 1998
Intermediate to advanced
848 pages
20h 13m
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 Appendix F, "The Standard 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'; ...Read now
Unlock full access