猿问

老师出的题,要求是要用递归算法写数字字符串转整形输出,求慕友帮帮忙

#include "stdio.h"
#include "conio.h"
#include "string.h"
int StrToInt(char *s)
{
//************************************************

//=================================================
}

int main()
{ char t[32];
// freopen("Str2Int.in", "r", stdin);
// freopen("Str2Int.out", "w", stdout);
gets(t);
printf("%d", StrToInt(t));
return 0;
}

扬帆大鱼
浏览 63回答 1
1回答

慕容708150

int delnum(char s[], int *p){int i,n,j;*p = NULL;n=strlen(s);for(i=0,j=0;i<n;i++)if(!(s[i]>='0'&&s[i]<='9'))s[j++]=s[i];else*p += s[i]-'0';s[j]='\0';return n-strlen(s);}void main(){char item[80] = "my2009xy3com+";int n,count;count=delnum(item,&n);printf("%s,count=%d,sum=%d",item,count,n);system("pause");}
随时随地看视频慕课网APP
我要回答