填空题
给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <string.h>
#include <stdlib.h<
#include <ctype.h<
char *fun(char *s)
inti, j, k, n; char *p, *t;
n=strlen(s)+1;
t=(c har*)malloc (n*sizeof(char));
p=(char*)malloc(n*sizeof(char));
j=0; k=0;
for(i=0; i<n; i++)
if(isdigit(s[i]))
/******************found*******************/
p[
(1)
]=s[i]; j++;
else
t[k]=s[i]; k++;
/******************found*******************/
for(i=0; i<
(2)
; i++)p[j+i]=t[i];
p[j+k]=0;
/******************found*******************/
return
(3)
;
main()
char s[80];
printf("Please input:");
scanf("%s", s);
printf("\nThe result is: %s\n", fun(s));
【参考答案】
j
点击查看答案
<上一题
目录
下一题>
热门
试题
问答题
给定程序中函数fun的功能是:首先把b所指字符串中的字符按逆序存放,然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到c所指数组中,过长的剩余字符接在c所指的数组的尾部。例如,当a所指字符串中的内容为“abcdefg”,b所指字符串中的内容为“1234”时,c所指数组中的内容应“a4b3c2dlefg”;而当a所指字符串中的内容为“1234”,b所指字符串的内容为“abcdefg”时,c所指数组中的内容应该为“lg2f3e4dcba”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> #include <string.h> void fun (char*a, char*, char *c) inti, j; char ch; i=0; j=strlen(b)-1; ******************found******************* while(i>j) ch=b[i]; b[i]=b[j]; b[j]=ch; i++; j--; while (*a|| *b) ******************found******************* If(*a) *c=*a; c++; a++; if(*b) *c=*b; c++; b++; *c=0; main() char s1[100], s2[100], t[200]; printf( nEnter s1 string: ); scanf( %s , s1); printf( nEnter s2 string: ); scanf( %s , s2); fun(s1, s2, t); printf( nThe result is: %s n , t);
点击查看答案&解析
单项选择题
以下叙述中错误的是( )。
A) gets函数用于从终端读入字符串
B) getchar函数用于从磁盘文件读入字符
C) fputs函数用于把字符串输出到文件
D) fwrite函数用于以二进制形式输出数据到文件
点击查看答案&解析
相关试题
p或(p)
k
函数fun的功能是:将s所指字符串中下标为偶...