944,008 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 13666
  • C RSS
Mar 17th, 2006
0

check number is string

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amen is offline Offline
17 posts
since Feb 2006
Mar 17th, 2006
0

Re: check number is string

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 17th, 2006
0

Re: check number is string

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Mar 17th, 2006
1

Re: check number is string

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.
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Jun 12th, 2010
-1

check number is string

what if we dont have to use library functions.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
anandmadhab is offline Offline
2 posts
since Jun 2010
Jun 12th, 2010
0
Re: check number is string
Well, in that case just do it the hard way -- put this in a loop
if( string[i] >= '0' || string[i] <= '9' )
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Corrupted stack ?
Next Thread in C Forum Timeline: calculate the execution time of a program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC