1 //输入一串字符串,将连接着的数字输出来,并统计有多少个整数
2 #include <stdio.h>
3 #include <tchar.h>
4 #include <process.h>
5 #include <string.h>
6 #include <stdlib.h>
7
8
9 int _tmain(int argc, _TCHAR* argv[])
10 {
11 char szText[2048];
12 scanf("%s",szText);
13
14 printf("你输入的是%s\n",szText);
15
16 int a[2048];
17 int aNum = 0;
18 int nLenText = strlen(szText);
19 int nStartNum = -1,nEndNum = -1;//数字起始位置
20 char *pStartChar = NULL, *pEndChar = NULL;
21 char szTempBuf[2048];
22 for(char *p = szText; ; p++)
23 {
24 char aChar = *p;
25 if(( aChar >= '0') && (aChar <= '9'))
26 {
27 if( pStartChar == NULL)
28 pStartChar = p;
29
30 }
31 else if(( aChar < '0') || (aChar > '9'))
32 {
33 pEndChar = p;
34
35 //找到一组数字
36 if(pStartChar != 0)
37 {
38 int nBufLen = pEndChar-pStartChar;
39 memcpy(szTempBuf,pStartChar,nBufLen);
40 szTempBuf[nBufLen] = 0;
41 int nNum = atoi(szTempBuf);
42 a[aNum]= nNum;
43 aNum++;
44 }
45 pStartChar = NULL;
46 if(*p == 0)
47 break;
48 }
49 if(*p == 0)
50 break;
51
52
53 }
54
55 printf("共有%d个整数\n",aNum);
56 for(int i = 0; i < aNum; i++)
57 {
58 printf("%d \n",a[i]);
59 }
60
61 getchar();
62 system("pause");
63
64 return 0;
65 }
66
67