1. So, what is the ispunct function in C?
The ispunct
function checks to determine if a value is a
punctuation character. Punctuation character being a mark that is used to either separate written
language elements or to clarify meaning. These punctuation marks fall on 4 different ranges on the ASCII table: [33, 47],
[58, 64], [91, 96] and [123, 126].
After receiving a value, the ispunct
function checks if it can
be found in one of the four ranges and returns a non-zero value, if a value can, in fact, be found. If
not, then zero is returned from this function, indicating that the received value is not a punctuation
mark.
Example 1: Usage of ispunct function in C.
#
include
<stdio.h>
#
include
<ctype.h>
int
main
()
{
char
*
str =
"Take a quiz :)"
;
int
i = 0, total = 0;
while
(str[i]
!=
'\0'
)
{
if
(
ispunct
(str[i]))
{
total++;
printf
(
"ispunct: %c\n"
, str[i]);
}
i++;
}
printf
(
"Total: %d"
, total);
return
(0);
}
Possible output:
ispunct: )
Total: 2