
For the ctype ispunct() operate, the purpose is to know that “punct” is brief for punctuation and never puncture. To place this operate to make use of it’s good to know what the library considers to be an ASCII punctuation character. It’s one more step ahead in my ongoing exploration of the ctype capabilities.
In accordance with the ispunct() operate, the next ASCII characters will not be thought of punctuation:
- All management codes
- The area
- Numbers
- Uppercase letters
- Lowercase letters
- The DEL character (code 127)
The next code makes use of the ispunct() operate to type out the lot of ASCII characters, from zero by means of 127 (the complete ASCII code vary):
2026_06_20-Lesson-a.c
#embody <locale.h>
#embody <wchar.h>
#embody <ctype.h>
void outwide(int c)
{
if( iscntrl(c) )
{
if( c==127 )
putwchar(9249);
else
putwchar(c+9216);
}
else
{
putwchar(c);
}
}
int major()
{
int ch;
setlocale(LC_ALL,"");
wprintf(L"Punctuation characters:n");
for( ch=0; ch<=127; ch++ )
if( ispunct(ch) )
outwide(ch);
putwchar(L'n');
wprintf(L"Not punctuation characters:n");
for( ch=0; ch<=127; ch++ )
if( !ispunct(ch) )
outwide(ch);
putwchar(L'n');
return 0;
}
I wrote the outwide() operate to keep away from some repetition within the major() operate. Its job is to output the vast character variations of the management codes (ASCII zero by means of 31) in addition to the DEL (code 127) as acceptable Unicode values.
The major() operate incorporates two for loops. Every one makes use of the ispunct() operate to check the worth of ASCII code ch. The primary loop outputs solely what are thought of to be punctuation characters. The second for loop outputs all of the non-punctuation characters, which incorporates all of the management codes in addition to the DEL.
Right here is pattern output:
Punctuation characters: !"#$%&'()*+,-./:;?@[]^_`~ Not punctuation characters: ␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz␡
Within the following code, I’ve written my very own ispunct() operate. I additionally borrowed the iscntrl() operate from final week’s Lesson:
2026_06_20-Lesson-b.c
#embody <locale.h>
#embody <wchar.h>
#embody <stdbool.h>
int iscntrl(int c)
c==127 )
return true;
else
return false;
int ispunct(int c)
{
if( c>=0 && c<=' ')
return false;
if( c>='0' && c<='9' )
return false;
if( c>='A' && c<='Z' )
return false;
if( c>='a' && c<='z' )
return false;
if( c==127 )
return false;
return true;
}
void outwide(int c)
{
if( iscntrl(c) )
{
if( c==127 )
putwchar(9249);
else
putwchar(c+9216);
}
else
{
putwchar(c);
}
}
int major()
{
int ch;
setlocale(LC_ALL,"");
wprintf(L"Punctuation characters:n");
for( ch=0; ch<=127; ch++ )
if( ispunct(ch) )
outwide(ch);
putwchar(L'n');
wprintf(L"Not punctuation characters:n");
for( ch=0; ch<=127; ch++ )
if( !ispunct(ch) )
outwide(ch);
putwchar(L'n');
return 0;
}
My ispunct() operate incorporates a towering sequence of if circumstances, every of which weeds out the non-punctuation characters as listed initially of this submit. I may have additionally written a switch-case construction to checklist the 32 characters that the ispunct() operate qualifies as punctuation. I may have additionally added the isalnum() operate (my very own model) to assist fish out the letters and numbers. Anyway, you get the concept.
For subsequent week’s Lesson, I wrap up this sequence on the ctype capabilities with the ultimate one: isxdigit().

