如果是判断十进制数
1 #include <stdio.h>
2
3 int getStrIntNum(char szStr[]) {
4
int i = 0, iCount = 0, bNumber = 0;
5
while (szStr[i] != '\0') {
6
if (szStr[i] >= 48
&&
szStr[i] <= 57) { // Number 0 ~ 9
=
ASCII 48 ~ 57
7
8
if (bNumber == 0) {
9
bNumber = 1;
10
}
11
}
12
else {
13
if (bNumber == 1) {
14
bNumber = 0;
15
iCount++;
16
}
17
}
18
i++;
19
}
20
21
return iCount;
22 }
23
24 int main(void) {
25
char szStr[] = "123ASM321C456C++654JAVA";
26
27
printf("%d\n", getStrIntNum(szStr));
28
29
return 0;
30 }
GCC run successfully.
[此贴子已经被作者于2016-8-29 09:01编辑过]