2. check whether a character is an integer or four lines of code from a string to a long integer function.

Source: Internet
Author: User

/************************************ **********************************/
/* 2. check whether a character is an integer or whether four Code ranges from a string to a long integer function */
/** **************************************** * ****************************/
// used to indicate whether to convert valid
bool is_chartointvalid = false;
int chartoint (char ch)
{< br> If (CH> = '0' & Ch <= '9')
is_chartointvalid = true;
return ch-'0 ';
}

// use the database function
long strtolong (const char * Str)
{< br> return atol (STR );
}< br> // four lines of code from a string to a long integer function
long strtolong1 (const char * Str)
{< br> int num = 0;
for (const char * temp = (* STR = '+' | * STR = '-')? STR + 1: Str); * temp> = '0' & * temp <= '9'; ++ temp)
num = 10 * num + * temp-'0';
return (* STR = '-'? -1: 1) * num;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.