test if a char is a digit or nondigit

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

test if a char is a digit or nondigit

Postby clarineterr » Sat Feb 20, 2010 1:38 am

is there a way to check if a char is a digit (ie a number between 0 and 9) or a letter or something else?
clarineterr
 
Posts: 12
Joined: Tue Jan 26, 2010 2:00 am

Re: test if a char is a digit or nondigit

Postby Wizard » Mon Feb 22, 2010 12:42 pm

char foo = '5'; // for example
if (foo >= '0' && foo <= '9')
{ // foo is a number
}
if (foo >= 'a' && foo <= 'z')
{ // foo is a lowercase letter
}
if (foo >= 'A' && foo <= 'Z')
{ // foo is an uppercase letter
}
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Re: test if a char is a digit or nondigit

Postby Alvaro » Mon Feb 22, 2010 2:45 pm

You can use isdigit(), isalpha(), etc., from <cctype>.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA


Return to Homeworks

Who is online

Users browsing this forum: No registered users and 1 guest