C Library - isdigit() function (2024)

The C ctype library isdigit() function checks if the passed character is a decimal digit character. This function is useful in various scenarios such as parsing numerical input from a user or processing data where digit validation is required.

Decimal digits are (numbers) − 0 1 2 3 4 5 6 7 8 9.

Syntax

Following is the C library syntax of the isdigit() function −

int isdigit(int c);

Parameters

This function accepts a single parameter −

  • c − This is the character to be checked, passed as an integer.This is an ASCII value of a character.

Return Value

Following is the return value −

  • The function returns a non-zero value (true) if the character c is a decimal digit (i.e., '0' through '9').
  • It returns 0 (false) if the character c is not a decimal digit.

Example 1: Simple Digit Check

The main function checks if the digits/character passed to it is a digit/ non-digit.

#include <stdio.h>#include <ctype.h>int main() { char ch = '5'; if (isdigit(ch)) { printf("'%c' is a digit.\n", ch); } else { printf("'%c' is not a digit.\n", ch); } return 0;}

Output

The above code produces following result−

'5' is a digit.

Example 2: Digit Check in a String

The below code demonstrates the use of isdigit in processing strings and identifying digits within them.

#include <stdio.h>#include <ctype.h>int main() { char str[] = "Hello123"; for (int i = 0; str[i] != '\0'; i++) { if (isdigit(str[i])) { printf("'%c' is a digit.\n", str[i]); } else { printf("'%c' is not a digit.\n", str[i]); } } return 0;}

Output

After execution of above code, we get the following result −

'H' is not a digit.'e' is not a digit.'l' is not a digit.'l' is not a digit.'o' is not a digit.'1' is a digit.'2' is a digit.'3' is a digit.

Advertisem*nts

C Library - isdigit() function (2024)
Top Articles
Real-World Applications of Blockchain Technologies
What are Bitcoin (BTC) whales up to? Why are they buying RenQ Finance (RENQ)
Camera instructions (NEW)
Tyson Employee Paperless
Coindraw App
Is Csl Plasma Open On 4Th Of July
The Best English Movie Theaters In Germany [Ultimate Guide]
Texas (TX) Powerball - Winning Numbers & Results
Craigslistdaytona
Unit 1 Lesson 5 Practice Problems Answer Key
Qhc Learning
Craigslist Mpls Cars And Trucks
Byte Delta Dental
DoorDash, Inc. (DASH) Stock Price, Quote & News - Stock Analysis
Canvas Nthurston
Gemita Alvarez Desnuda
Craigslist Toy Hauler For Sale By Owner
91 East Freeway Accident Today 2022
Saritaprivate
Kamzz Llc
Epguides Strange New Worlds
Sulfur - Element information, properties and uses
The BEST Soft and Chewy Sugar Cookie Recipe
Busted Mcpherson Newspaper
Morse Road Bmv Hours
Nsa Panama City Mwr
Johnnie Walker Double Black Costco
Loslaten met de Sedona methode
Turbo Tenant Renter Login
Tire Plus Hunters Creek
Jail Roster Independence Ks
Winterset Rants And Raves
Imagetrend Elite Delaware
Http://N14.Ultipro.com
Half Inning In Which The Home Team Bats Crossword
The Wichita Beacon from Wichita, Kansas
Weekly Math Review Q4 3
Today's Final Jeopardy Clue
Magicseaweed Capitola
Dr. John Mathews Jr., MD – Fairfax, VA | Internal Medicine on Doximity
Dying Light Nexus
B.C. lightkeepers' jobs in jeopardy as coast guard plans to automate 2 stations
How Many Dogs Can You Have in Idaho | GetJerry.com
Doordash Promo Code Generator
Charli D'amelio Bj
Kenner And Stevens Funeral Home
Academic Notice and Subject to Dismissal
Ucla Basketball Bruinzone
Haunted Mansion (2023) | Rotten Tomatoes
Fredatmcd.read.inkling.com
Fallout 76 Fox Locations
2000 Fortnite Symbols
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 5544

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.