填空题
请补充main函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1指向原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。
例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define LEN 80
main()
char str1[LEN],str2[LEN];
int n,i;
clrscr();
printf("Enter the string:\n");
gets(str1);
printf "Enter the position of the string deleted:");
scanf(
【1】
);
for(i=0;i<n;i++)
【2】
str2[i]=‘\0’;
printf("The new string is:%s\n",
【3】
);
【参考答案】
[1] "%d",&n [2] str2[i]=str1[i] [3] str2
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
下列程序定义了NXN的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N]),该函数的功能是使数组右上半三角元素中的值全部置成0。例如a数组中的值为 a=4 5 6 1 7 9 3 2 6, 则返回主程序后a数组中的值应为 0 0 0 1 0 0 3 2 0 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include<conio.h> #include<stdio.h> #include<stdlib.h> #define N 5 int fun(int a[ ][N]) main() int a[N][N],i,j; clrscr( ); printf( *****The array***** n ); for(i=0;i<N;i++) *产生—个随机的5*5矩阵* for(j=0;j<N;j++) a[i][j]=rand( )%10; printf ( %4d ,a[i][j]); printf( n ); fun(a); printf( THE RESULT n ); for(i=0;i<N;i++) for(j=0;i<N;j++) printf( %4d ,a[i][j]); printf( n );
点击查看答案&解析
填空题
下列给定程序中,函数fun()的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<stdio.h> #include<conio.h> void fun(char*S) int i,j; for(i=0,j=0;s[i]! =’ 0’;i++) *************found************ if((s[i]>=’A’&&s[i]<=’Z’)&&(s[i]>= ’a’&&S[i]<=’z’,)) s[j++]=s[i]; *************found************* s[j]= 0 ; main() char item[80]; clrscr(); printf( nEnter a string: ); gets(item); printf( n nThe string is: %s n ,item); fun (item); printf( n nThe string of changing is: %S n ,item);
点击查看答案&解析
相关试题
下列程序定义了NXN的二维数组,并在主函数...
下列给定程序中,函数fun()的功能是:依...