C–Question

这里留言就可以了我每天都看

2级c语言模拟考试题:

上机部分
一、填空题
请补充函数fun( ),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void fun(char *s)
{
int i=0;
char *p=s;
while (【1】)
{
if ( *p>=’a’ && *p<=’z’)
{
s=*p;
【2】;
}
p++;
}
s=【3】;
}
void main( )
{
char str[80];
system(”CLS”);
printf(”\nEnter a string:”);
gets(str);
printf(”\n\nThe string is: %s\n”,str);
fun(str);
printf(”\n\nThe string of changing is : %s\n”,str);
}
二、改错题
下列给定程序中,函数fun()功能是:将m(1<=m<=10)个字符串反着连接起来,组成一个新串,放入pt所指字符串中,例如:把3个串DEG,ac,df反着串联起来,结果是dfacDEG。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main( )函数,不得增加或者删行,也不得改变程序的结构。
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
void fun (char str[ ][10], int m, char *pt)
{
int k,q,i,j=0;
/**********found**********/
for(k=m;k>0;k–)
{
q=strlen(str[k]);
j+=q;
for(i=0;i<q;i++)
pt=str[k];
pt+=q;
pt[0]=0;
}
/***********found********/
pt=j;
}
void main( )
{
int m,h;
char s[10][10],p[120];
system(”cls”);
printf(”\n please enter m:”);
scanf(”%d”,&m);
printf(”\n please enter %d string:\n”,m);
gets(s[0]);
for(h=0;h<m;h++)
gets(s[h]);
fun(s,m,p);
printf(”\n the result [...]

Tags:

Continue to Read