字符串中取出数字字符串
#include "stdafx.h"
#include "iostream"
#include <ctime>
using namespace std;
//getNum()获得数字字符串函数
char * getNum(char *src, char *buf)
{
while (* src!='\0')
{
if (isdigit(*src))
{
break;
}
src++;
}
if (* src=='\0')
{
return '\0';
}
while (isdigit(*src))
{
*buf = *src;
buf++;
src++;
}
*buf = '\0';
return src;
}
int _tmain()
{
char str[100], digits[20];
cin.getline(str, 100);
char* p = str;
int i = 1;
//如果p等于空结束循环
while ((p=getNum(p,digits))!=NULL)
{
cout << "digit string " << i << " is " << digits << endl;
i++;
}
}