#include <stdio.h> int main(void) { char in[] = "1,2,3,15,30"; //输入的字符串,忽略输入过程 char *p=in; int a,n,sum=0; while (*p) { if (sscanf(p,"%d%n",&a,&n) == 1) { sum += a; printf("%d ",a); p += n; } else ++p; } printf("\nsum=%d\n",sum); return 0; }
[此贴子已经被作者于2021-11-21 20:32编辑过]