C或C++高手进来帮下忙

来源:百度知道 编辑:UC知道 时间:2024/09/12 22:33:04
在键盘上输入一连串字符串,如df35f45dds678df89df#ghjgj45df,
将所输入字符里的数字相连的分配到数组里面去,并且以#符号代表读入数据停止,即上面得字符中有678,89被分配到了数组a[0][0],a[0][1]中。
请问怎样实现
谢谢了
如果觉得分不够高小弟愿意再加,分不多- -!

#include <stdio.h>
#include <string.h>

int stringToInt(char ch[])
{
int strLength=strlen(ch);
int tmNumber=0,j=1;
for (int i=strLength-1;i>=0;i--)
{
tmNumber+=(ch[i]-48)*j; //-48即字符变成数字
j*=10;
}
return tmNumber;
}

void StrToArray(char ch[],int resultInt[])
{
int clength=strlen(ch);
char tempInt[40]="";//存临时数字串的
int tempCount=0,j=0;
for (int i=0;i<clength;i++)//遍历字符串
{
if (ch[i]=='#')//判断是否#号
{
break;//跳出for,并不返回
}
if (ch[i]>='0'&&ch[i]<='9')//数字
{
tempInt[tempCount]=ch[i];//拷贝到临时数字串
tempCount++;
if (ch[i+1]<'0'||ch[i+1]>'9') //判断一下下一个字符
{
tempInt[tempCount]='\0';//拷入结束字符
resultInt[j]=stringToInt(tempInt);//把临时字符串转换成数字存入数组
j++;
tempCount=0;
}
}