check number is string

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2006
Posts: 17
Reputation: amen is an unknown quantity at this point 
Solved Threads: 0
amen amen is offline Offline
Newbie Poster

check number is string

 
0
  #1
Mar 17th, 2006
how to check there exist number in string using isalpha.if number exist, display "only alphabetic,please input again"

example :
user input = i had to 2 number
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: check number is string

 
0
  #2
Mar 17th, 2006
Is it really that hard?

  1. if(isalpha(char))

I don't know if that takes a string or not, but if it's only a character then just loop through.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,660
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: check number is string

 
0
  #3
Mar 17th, 2006
If isalpha() failes it does not mean that the character is a numeric digit, it could be anything else too. If you want to check for numeric digits then use isdigit(). And both only check one character, so if you have a whole string then you must check each character individually.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: check number is string

 
1
  #4
Mar 17th, 2006
If you want to make sure there are no numbers in a string, you can do a find_first_of( "01234567890"). If it equals anything other than string::npos, it's got a number in there.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6570 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC