"C language" for the following function prototype write function definition, this string parameter must contain one or more numbers, the function should convert these numeric characters to an integer and return this integer.

Source: Internet
Author: User
Tags function prototype
/* Write the function definition for the following function prototype: int Ascii_to_integer (char *str); This string argument must contain one or more numbers, and the function should convert the numeric characters to integers and return the integer. If the string argument contains any non-numeric characters, the function returns zero. Please do not worry about arithmetic overflow. Tip: The trick is simple: Every number you find, multiply the current value by 10, and add the value to the value represented by the new number */#include <stdio.h>int ascii_to_integer (char const *STR) {int sum = 0;int P;while (*str! = ') {if (*str >= ' 0 ' && *str <= ' 9 ') {p = (int) (*STR)-sum = SUM * 1 0 + p;str++;} Elsereturn 0;} return sum;} int main () {    char *p = "124few";p rintf ("converted to:%d\n", Ascii_to_integer (p)); return 0;}


"C language" for the following function prototype write function definition, this string parameter must contain one or more numbers, the function should convert these numeric characters to an integer and return this integer.

Related Article

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.