old-www/LDP/LG/issue38/rogers.html

147 lines
5.9 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="James M. Rogers">
<META NAME="Description" CONTENT="This article is the second in a series designed to explore the Standard C library implementation available for Linux">
<META NAME="Keywords" CONTENT="linux, standard c library, character functions">
<META NAME="Classification" CONTENT="Second Year Programming">
<META NAME="GENERATOR" CONTENT="Mozilla/4.07 [en] (X11; I; Linux 2.0.36 i586) [Netscape]">
<TITLE>The Standard C Library for Linux Issue 32</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#A000A0" ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<CENTER>
<H1>
<FONT COLOR="#800000">The Standard C Library for Linux</FONT></H1></CENTER>
<CENTER>
<H3>
<FONT COLOR="#000080">Part Four: &lt;ctype.h&gt; Character Handling</FONT></H3></CENTER>
<CENTER>
<H4>
By <A HREF="mailto:jrogers@u.washington.edu">James M. Rogers</A></H4></CENTER>
<HR>
<P>The last article was on &lt;stdio.h&gt; Input and Output.&nbsp; This article
is on &lt;ctype.h&gt; character handling.
<P>Character handling allows us to clasify characters as alpha, digit,
hexdigit, whitespace, printable, lowercase, uppercase, punctuation and
to map to and from the upper and lowercase alphabets.&nbsp; Most importantly
&lt;ctype.h&gt; implements these functions in a non-system dependent way.
<P>If you write your program assuming that every computer is an ASCII computer
you will have trouble porting your program to non ASCII machines. If you
write your character handling functions in terms of these functions your
program will be much more portable to other platforms.
<P>I am assuming a knowledge of c programming on the part of the reader.&nbsp;
There is no guarantee of accuracy in any of this information nor suitability
for any purpose.
<P>The program example that I will do this month will go thru the entire
8bit ASCII range and tell us to which classes any one chacter belongs.&nbsp;
The example is <A HREF="./rogers_example04c.txt">rogers_example04.c</A><TT>.</TT>
The output the program generates will be an html document and the run from
my system is <A HREF="./rogers_example04.html">rogers_example04.html</A>
.
<BR>This program can be used as a cgi-bin&nbsp; script and is a demonstration
of the flexibility of the c language.
<BR>&nbsp;
<P>As always, if you see an error in my documentation please tell me and
I will correct myself in a later document.&nbsp; See corrections at end
of the document to review corrections to the previous articles.
<P><B><FONT SIZE="+1">Character Handling</FONT></B>
<PRE>
#include &lt;ctype.h&gt;
int isalpha(int c);
int isalnum(int c);
int isdigit(int c);
int isxdigit(int c);
int iscntrl(int c);
int isspace(int c);
int ispunct(int c);
int isgraph(int c);
int isprint(int c);
int islower(int c);
int isupper(int c);
int tolower(int c);
int toupper(int c);
</PRE>
isalpha returns true if the character is in the range of A-Z or a-z.
<P>isalnum returns true if the character is in the range of A-Z or a-z
or 0-9.
<P>isdigit returns true if the character is in the range of 0-9.
<P>isxdigit returns true if the character is in the range of 0-9 or a-f
or A-F.
<P>iscntrl returns true if the character is in the set (FF, NL, CR, HT,
VT, BEL or BS).
<P>isspace returns true if the character is in the set (space, FF, NL,
CR, HT or VT).
<P>ispunct returns true if the character is a nonalnum, nonspace and noncntrl.
<P>isgraph returns true if the character isalnum or ispunct.
<P>isprint returns true if the character isspace or isgraph.
<P>islower returns true if the character is in the range of a-z.
<P>isupper returns true if the character is in the range of A-Z.
<P>tolower if isupper return the lowercase character otherwise return the
character.
<P>toupper if islower return the uppercase character otherwise return the
character.
<BR>&nbsp;
<P>
<HR>
<H4>
Bibilography:</H4>
<I>The ANSI C Programming Language, Second Edition</I>, Brian W. Kernighan,
Dennis M. Ritchie, Printice Hall Software Series, 1988
<P><I>The Standard C Library</I>, P. J. Plauger, Printice Hall P T R, 1992
<P><I>The Standard C Library, Parts 1, 2, and 3</I>, Chuck Allison, <I>C/C++
Users Journal</I>, January, February, March 1995
<P>CTYPE(3), BSD MANPAGE, <I>Linux Programmer's Manual</I>, 29 November
1993
<BR>
<HR>
<BR>&nbsp;
<CENTER>
<H4>
Previous "The Standard C Library for Linux" Articles</H4></CENTER>
<A HREF="http://www.linuxgazette.com/issue24/rogers.html"><I>The Standard
C Library for Linux, Part One</I>, James M. Rogers, January 1998</A>
<BR><A HREF="http://www.linuxgazette.com/issue31/rogers1.html"><I>The Standard
C Library for Linux, Part Two</I>, James M. Rogers, July 1998</A>
<BR><A HREF="http://www.linuxgazette.com/issue32/rogers.html"><I>The Standard
C Library for Linux, Part Three</I>, James M. Rogers, August 1998</A>
<BR>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1999, James M. Rogers <BR>
Published in Issue 38 of <i>Linux Gazette</i>, March 1999</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./adler1.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./kidd.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->