编程实现输入一个字符串,将其中连续的数字作为一个整数,依次存放到数组a中。例如:字符串为“ab123&gh6741

如题所述

第1个回答  2011-04-17
什么语言?
c语言如下:
void stoarray(char s[],int n[]){
int i=0,j,k=0;
char t[12];//因为整型int约在2000000000内的。
for(j=0,k=0;j<strlen(s);j++){
if(s[j]<='9'&&s[j]>='0'){
t[k++]=s[j];
}else if(k!=0){
t[k]='\0';
k=0;
n[i++]=stoi(t);
}
}
if(k!=0){
t[k]='\0';
k=0;
n[i++]=stoi(t);
}
}本回答被提问者采纳
相似回答