Digital extraction: enter a carriage return flag for the end of the string (less than 10 characters), which extracts all numeric characters, convert it to a decimal integer output.

#include <stdio.h>

void main() {
    int i = 0, number = 0;
    char str[10];
    printf("Please enter a string:");
    while ((str[i] = getchar()) != '\n')
        i++;
    str[i] = '\0';
    for (i = 0; str[i] != '\0'; i++)
        if (str[i] >= '0' && str[i] <= '9')
            number = number * 10 + str[i] - '0';
    printf("digit=%d\n", number);
}
Published 139 original articles · won praise 3 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104828778