The ctype.h Character Functions and Strings

Chapter 7, “C Control Statements: Branching and Jumps,” introduced the ctype.h family of character-related functions. These functions can't be applied to a string as a whole, but they can be applied to the individual characters in a string. Listing 11.26, for example, defines a function that applies the toupper() function to each character in a string, thus converting the whole string to uppercase. It also defines a function that uses ispunct() to count the number of punctuation characters in a string.

Listing 11.26. The convert.c Program
 /* convert.c -- modifies a string */ #include <stdio.h> #include <string.h> #include <ctype.h> #define LIMIT 80 void ToUpper(char *); int PunctCountt(const char *); ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.