Raised This Month: $51 Target: $400
 12% 

How Can I Check Char is number?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zeisen
Member
Join Date: Nov 2016
Location: Republic of Korea
Old 01-17-2017 , 16:47   How Can I Check Char is number?
Reply With Quote #1

I want make a bool returns function string is number or not.
I want like:

Code:
char Hello[] = "123123";
bool result = IsNumber(Hello, sizeof(hello));
PrintToChatAll("result : %d", result); // it will print 1

Code:
char Hello[] = "World!";
bool result = IsNumber(Hello, sizeof(hello));
PrintToChatAll("result : %d", result); // it will print 0

Last edited by Zeisen; 01-17-2017 at 16:48.
Zeisen is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 01-17-2017 , 17:06   Re: How Can I Check Char is number?
Reply With Quote #2

PHP Code:
bool IsStringNumeric(const char[] str)
{
    
int len strlen(str);
    for (
int i str[0] == '-' 0leni++)
        if (!
IsCharNumeric(str[i]))
            return 
false;
    return 
true;

Note: "-" string also will valid. Add check if needed.

Last edited by Kailo; 01-17-2017 at 17:10.
Kailo is offline
Zeisen
Member
Join Date: Nov 2016
Location: Republic of Korea
Old 01-17-2017 , 23:21   Re: How Can I Check Char is number?
Reply With Quote #3

Quote:
Originally Posted by Kailo View Post
PHP Code:
bool IsStringNumeric(const char[] str)
{
    
int len strlen(str);
    for (
int i str[0] == '-' 0leni++)
        if (!
IsCharNumeric(str[i]))
            return 
false;
    return 
true;

Note: "-" string also will valid. Add check if needed.
Thanks for Reply!
Zeisen is offline
nxlinux
Member
Join Date: Oct 2013
Location: China
Old 01-19-2017 , 04:17   Re: How Can I Check Char is number?
Reply With Quote #4

great!
nxlinux is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode