简答题 C语言
题号 #2257053

请编写函数proc(),其功能是:将str所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
例如,当str所指字符串中的内容为ABCDEFGHIJK (输入完成以空格、Tab或者Enter键加任意非空格、Tab或者Enter键的一个字符作为输入结束标志),则在t所指数组中的内容应是BDFHJ。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void proc(char*str,char t[])
{

}
void main()
{
int i=1:
char str[100],t l00];
system("CLS"):
print{("\nPleast enter string Str:");
scanf("%s\n".str);
proc(str,t);
print{("\nThe lesult is:%s\n",t);
}

进入在线模考

参考答案

暂无

答案解析

void proc(char*str,char t[])
{
int i,j=0,k=strlen(str);//s所指字符串中下标为
偶数的字符删除即跳过去,对其什么也小做
for(i=1;i<k;i=i+2)
t[j++]=str[i];//把下标为奇数的数,放到t数
组中
t[j]='\0 ';//最后用'\0 '作为字符串结束标志
}
【解析】按照题目中要求,将str所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在1所指数组中。可以通过将字符串str中下标为奇数的字符放到字符串t中,对字符串str中的其余字符不予处理。最后为新的字符串数组添加结束符。

你可能感兴趣的试题

1

下列给定程序中,函数proc()的功能是:对M名学生的学习成绩,按从高到低的顺序找出前m(m≤l0)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<conio.h>
#define M 10
typedef struct SS
{
char num[10];
int order;
}
STU:
STU*proc(STU a[],int m)
{
STU b[M],*tt;
int i,j,k;
【1】 ;
for(i=0:i<M:i++)
b[i]=a[i];
for(k=0;k<m;k++)
{
for(i=j=0;i<M;i++)
if(【2】 }
j=i;
tt[k]=b[j]:
b[j].order=0;
}
return 【3】 ;
}
void outresult(STU a[],FILE*pf)
{
int i;
for(i=0;i<M;i++)
printf(pf,"No=%S Mark=%d\n",
a[i].hum,a[i].order);
fprintf(pf,"\n\n");
}
void main()
{
STU stu[M]={{"A01",60),{"A02",90},
{"A03",88),{"A04",76),{"A05",63},
{"A06",69),{"A07",100),{"A08",87),
{"A09",66),{"A10",95));
STU*porder;
int i,m;
system("CLS");
printf("***The Origial data***\n");
outresult(stu,stdout);
print{("\nGive the numeber of the
students who have better score:");
scanf("%d",&m);
while(m>10)
{
printf("\nGive the number of the
studets who have better score:");
scan{("%d",&m);
}
porder=proc(stu,m);
print{("***THE RESULT***\n");
print{("***The top students***\n");
for(i=0;i<m;i++)
printf("%S%d\n",
porder[i].num,porder[i].order);
free(porder);
}

找试题 · 找答案 · 找资料 在线模考