#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> void check(char *s) { //检查字符串出现了 不是空格,也不是数字的的字符,直接退出。 int l, i; l = strlen(s); for(i = 0; i < l; i++) if(!isspace(s[i]) && !isdigit(s[i])) exit(0); return ; } char *get_next(char *s) { //得到下一个,要处理的字符串的开头 int i = 0; char *s1 = s; while(isspace(s[i])) i++; while(isdigit(s[i])) i++; return (s1+i); } int f(char *s) { //计算一个字符串,并把字符串中连续的数字,当一个int的数字处理。 int n, i; n = 0; while(*s != NULL) { i = atoi(s); n += i; s = get_next(s); } return n; } int main() { char s[100]; int n; gets(s); check(s); n = f(s); printf("%d/n", n); return 0; }