A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
ispunct returns nonzero for printable characters that are not letters, digits, or whitespace. That includes punctuation marks, mathematical symbols, and special characters like ! @ # $ % ^ & * ( ) - _ + = { } [ ] | \ : ; " ' < > , . ? / ~ `. It is the complement of the alphanumeric-plus-space set within the printable range. Use it for tokenizing, sanitizing, and detecting special characters in input.
#include <stdio.h>#include <ctype.h>int main(void) {const char *input = "Hello, World! (2026) [test]";printf("Punctuation in \"%s\":\n", input);for (const char *p = input; *p; p++) {if (ispunct((unsigned char)*p)) {printf(" '%c' (0x%02X)\n", *p, (unsigned char)*p);}}return 0;}
Six punctuation characters extracted from the input. Letters, digits, and spaces were skipped. The parentheses and brackets are classified as punctuation, not as letters or whitespace. This classification follows the C locale. In other locales, additional characters might be classified differently.
ispunct completes the printable character classification: isalpha for letters, isdigit for digits, isspace for whitespace, ispunct for everything else that is printable. Next: isspace, for detecting whitespace characters including tabs and newlines.
Finish the lesson once you have worked through the material. This awards ★ 10 XP.