问答题

给定程序中,函数fun的功能是将a和b所指的两个字符串分别转换成面值相同的整数,并进行相加作为函数值返回,规定字符串中只含9个以下数字字符。 例如,主函数中输入字符串”32486”和”12345”,在主函数中输出的函数值为44831。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构! 试题程序: 1 #include<stdio.h> 2 #include<string.h> 3 #include<ctype.h> 4 #define N 9 5 long ctod(char*s) 6 { long d=0; 7 while(*S) 8 if(isdigit(*s)) { 9 /*********found*********/ 10 d=d*10+*s- 【1】 ; 11 /*********found*********/ 12 【2】 ; 13 } 14 return d; 15 } 16 long fun(char*a,char*b) 17 { 18 /*********found*********/ 19 return 【3】 ;j 20 } 21 main() 22 { char s1[N],s2[N]; 23 do 24 { printf("Input string s1:"); 25 gets(s1);} 26 while(strlen(s1)>N); 27 do 28 {printf("Input string s2:"); 29 gets(s2);} 30 while(strlen(s2)>N); 31 printf("The result is:%ld\n",fun(s1,s2)); 32 }

【参考答案】

正确答案:(1)’0’ (2)s++或++s (3)ctod(a)+etod(b)
热门 试题