ctype.h in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

Every character belongs to a specific character type, such as alphabets, digits, punctuation, etc. The ctype header file in C declares various functions to check whether a character belongs to a particular character class. It also contains functions to transform the characters.

Introduction

The syntax to include ctype is:

or

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

What is ctype.h in C?

The ctype header file in C defines various functions to classify and transform characters. These functions take an integer(ASCII value of the character) as an input. If the input is not an integer, it is typecasted internally in the function.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Character Classes

A character class is a set of characters belonging to some type. In this section, we will see the various character sets present in C.

  • Digits: It is the set of numeric characters, i.e.,{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.

  • Hexadecimal digits: It is the set of hexadecimal digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}. The hexadecimal number system is the type of number system which has a base of 16.

  • Lowercase letters: It is the set of lowercase alphabets {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}.

  • Uppercase letters: It is the set of uppercase alphabets {A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z}.

  • Letters: It is the set of all alphabets, uppercase, and lowercase.

  • Alphanumeric characters: It is the set of all alphabets(uppercase and lowercase) and digits.

  • Punctuation characters: It is the set of all punctuation characters ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ | ~ {}

  • Graphical characters: It is the set of all characters with a graphical representation. This includes letters, digits, and punctuation characters.

Note: The whitespace characters (' ') are not considered graphical characters.

  • Space characters: It is the set of characters that produces a white space. These are as follows.

    CharacterDescription
    ' 'space
    '\n'newline
    '\t'horizontal tab
    '\v'vertical tab
    '\f'form feed
    '\r'Carriage return
  • Printable characters: The set of alphabets(lowercase or uppercase), numbers, punctuation characters, and space characters.

  • Control characters: Control characters are those who are not printed on the screen. Some examples are backspace, tab, shift, etc.

  • Blank characters: It is the set of space character(' ') and tab character('\t').

  • Alphabetic characters: The set of all alphabets, uppercase, and lowercase.

The Functions Defined in the Header ctype.h

  • isalnum: This function returns a non-zero number if the argument is an alphabet('a' - 'z' or 'A' - 'Z') or a number('0' - '9'). It returns zero in all other cases.

    Syntax:

  • isalpha: This function returns a non-zero number if the argument is an alphabet('a' - 'z' or 'A' - 'Z') and zero otherwise.

    Syntax:

  • iscntrl: This function returns a non-zero number if the argument is a control character and zero otherwise.

    Syntax:

  • isdigit: This function returns a non-zero number if the argument is a numeric character('0' - '9') and zero otherwise.

    Syntax:

  • isgraph: This function returns a non-zero number if the argument is a graphic character and zero otherwise.

    Syntax:

  • islower: This function returns a non-zero number if the argument is a lowercase alphabet character('a' - 'z') and zero otherwise.

    Syntax:

  • isprint: This function returns a non-zero number if the argument is a printable character and zero otherwise.

    Syntax:

  • ispunct: This function returns a non-zero number if the argument is a punctuation character and zero otherwise.

    Syntax:

  • isspace: This function returns a non-zero number if the argument belongs to the space character class and zero otherwise.

    Syntax:

  • isupper: This function returns a non-zero number if the argument is an uppercase alphabet character('A' - 'Z') and zero otherwise.

    Syntax:

  • isxdigit: This function returns a non-zero number if the argument is a hexadecimal character and zero otherwise.

    Syntax:

  • tolower: If the argument is an uppercase alphabet, the function converts it into a lowercase alphabet. Else, it returns the same character.

    Syntax:

  • toupper: If the argument is a lowercase alphabet, the function converts it into an uppercase alphabet. Else, it returns the same character.

    Syntax:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The ctype header file in C defines functions to classify and transform characters in various character classes.
  • A character class is a set of characters belonging to the same type.
  • These functions take an integer(ASCII value of the character) as an input. If the input is not an integer, it is typecasted internally in the function.