1.\" $NetBSD: ctype.3,v 1.21 2010/05/06 11:46:11 jruoho Exp $ 2.\" 3.\" Copyright (c) 1991 Regents of the University of California. 4.\" All rights reserved. 5.\" 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)ctype.3 6.5 (Berkeley) 4/19/91 32.\" 33.Dd May 6, 2010 34.Dt CTYPE 3 35.Os 36.Sh NAME 37.Nm isalpha , 38.Nm isupper , 39.Nm islower , 40.Nm isdigit , 41.Nm isxdigit , 42.Nm isalnum , 43.Nm isspace , 44.Nm ispunct , 45.Nm isprint , 46.Nm isgraph , 47.Nm iscntrl , 48.Nm isblank , 49.Nm toupper , 50.Nm tolower , 51.Nd character classification and mapping functions 52.Sh LIBRARY 53.Lb libc 54.Sh SYNOPSIS 55.In ctype.h 56.Fn isalpha "int c" 57.Fn isupper "int c" 58.Fn islower "int c" 59.Fn isdigit "int c" 60.Fn isxdigit "int c" 61.Fn isalnum "int c" 62.Fn isspace "int c" 63.Fn ispunct "int c" 64.Fn isprint "int c" 65.Fn isgraph "int c" 66.Fn iscntrl "int c" 67.Fn isblank "int c" 68.Fn toupper "int c" 69.Fn tolower "int c" 70.Sh DESCRIPTION 71The above functions perform character tests and conversions on the integer 72.Ar c . 73.Pp 74See the specific manual pages for information about the 75test or conversion performed by each function. 76.Sh EXAMPLES 77To print an upper-case version of a string to stdout, 78the following code can be used: 79.Bd -literal -offset indent 80const char *s = "xyz"; 81 82while (*s != '\e0') { 83 putchar(toupper((int)(unsigned char)*s)); 84 s++; 85} 86.Ed 87.Sh SEE ALSO 88.Xr isalnum 3 , 89.Xr isalpha 3 , 90.Xr isblank 3 , 91.Xr iscntrl 3 , 92.Xr isdigit 3 , 93.Xr isgraph 3 , 94.Xr islower 3 , 95.Xr isprint 3 , 96.Xr ispunct 3 , 97.Xr isspace 3 , 98.Xr isupper 3 , 99.Xr isxdigit 3 , 100.Xr tolower 3 , 101.Xr toupper 3 , 102.Xr ascii 7 103.Sh STANDARDS 104These functions, with the exception of 105.Fn isblank , 106conform to 107.St -ansiC . 108All described functions, including 109.Fn isblank , 110also conform to 111.St -p1003.1-2001 . 112.Sh CAVEATS 113The first argument of these functions is of type 114.Vt int , 115but only a very restricted subset of values are actually valid. 116The argument must either be the value of the macro 117.Dv EOF 118(which has a negative value), 119or must be a non-negative value within the range representable as 120.Vt unsigned char . 121Passing invalid values leads to undefined behavior. 122.Pp 123Values of type 124.Vt int 125that were returned by 126.Xr getc 3 , 127.Xr fgetc 3 , 128and similar functions or macros 129are already in the correct range, and may be safely passed to these 130.Nm ctype 131functions without any casts. 132.Pp 133Values of type 134.Vt char 135or 136.Vt signed char 137must first be cast to 138.Vt unsigned char , 139to ensure that the values are within the correct range. 140The result should then be cast to 141.Vt int 142to avoid warnings from some compilers. 143Casting a negative-valued 144.Vt char 145or 146.Vt signed char 147directly to 148.Vt int 149will produce a negative-valued 150.Vt int , 151which will be outside the range of allowed values 152(unless it happens to be equal to 153.Dv EOF , 154but even that would not give the desired result). 155