用C语言 用指针找出字符串中的数字并相加,输出asII值。例,a1b2c3 怎么做
1 回答
denmushi
TA贡献9条经验 获得超0个赞
#include <stdio.h>
int main(){
char str[] = "a1b2c3";
char* p = str;
int s = 0;
printf("数字有:");
while(p){
if(*p>='0'&&*p<='9'){
s += (*p - '0');
printf("%d",*p - '0');
}
p++;
}
printf("\n求和为:%d\nASCII码为:%d\n",s,s+'0');
return 0;
}- 1 回答
- 0 关注
- 1266 浏览
添加回答
举报
0/150
提交
取消
