题库 题库

【简答题】

假定输入的字符串中只包含字母和*号。请编写函数proc(),它的功能是:将字符串中的前导*号全部删除,中间和后面的*号不删除。
例如,若字符串中的内容为****a*bc*def*g** **,删除后,字符串中的内容则应当是a*bc*def*g** **。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<STDIO.h=:{>
#include<CONIO.h>
woid proc(char*st r)
{
}
void main()
char str[81];
printf("Enter a string:\n");
gets(str);
proc(str):
printf("The string after deleted:\n");
puts(str);}

参考答案

void proc(char*str)
{
char*p=str:
while(*p=='*')p++;//通过P的移动来达
到使P指向第一个不是*号的字符
for#;*p!='\0 ';p++,str++#//把从第一个
不是*号的字符放到a中 ‘
 *str=* P: *str='\0 ';
//最后用'\0'作为字符串结束标志
}

相关试题

单选题 若输入“abcdef”“abdef”,下述程序的输出结果为( )。
#include
#include
main()
{ int n;
char s1[20],s2[20],*p1,*p2;
scanf("%s",s1);
scanf("%S",s2);
p1=s1;
p2=s2;
n=strcmp(p1,p2);
printf("Vood\n",n);
}
查看答案
单选题 下列程序的输出结果是( )。
#included stdi0.h>
#included string.h>
void fun(int b[])
{ static int i=0;
do
{ b[i]+=b[i+1];
}while(++i<2);
}
main()
{ int k,a[5]={1,3,5,4,9};
fun(a);
for(k=0;k<5;k++)printf("%d",a[k]);
}
查看答案
单选题 若二维数组a有m列,则在a[i][j]前的元素个数为( )。 查看答案
单选题 下列程序的输出结果是( )。
#include
int fun(int a)
{ int b=0;
static int c=4:
a=c++:b++;
return(a):
main()
{ int a=2,i,c;
for(i=0:i<2;i++)
c=f(a+1):
printf("%d\n",c);
}
查看答案
单选题 有下列函数定义:
fun(float h)
{ printf("%f,%f\n",h,h*h);)
该函数的类型是( )。
查看答案
单选题 已知有如下结构体:
struct sk
{ int a;
float b;
}data,*p;
若有P=&data,则对data的成员a引用正确的是( )。
查看答案
单选题 有以下程序
int fun(int x,int y){return(x+y);} main()
{ int a=1,b=2,C=3,sum;
sum=fun((a++,b++,a+b),c++
printf("%d\n",sum);)
执行后的输出结果是( )。
查看答案
单选题 下列叙述中正确的是( )。 查看答案
单选题 以下叙述中错误的是( )。 查看答案
单选题 若有定义:“int a=4,b=5;float x=3.4,y=2.1;”,则下列表达式的值为( )。
(float)(a+b)/2+(int)x%(int)y;
查看答案
单选题 有以下程序段
int j;float y;char name[50]:
scanf("%2d%f%s",&i,&.y,name):
当执行上述程序段,从键盘上输入55566 7777abc后,y 的值为( )。
查看答案
单选题 若有以下程序:
int a=1,b=2:
a=a^b:
b=b^a:
则执行以上语句后a和b的值分别是( )。
查看答案
单选题 下列叙述中正确的是( )。 查看答案
单选题 下列程序执行后的输出结果是( )。
void func(int*a,int b[])
{ b[0]=*a+b;}
main()
{ int a,b[5];
a=0.b[0]=3;
func(&a,b);printf("%d\n",b[0]);
}
查看答案
单选题 C语言结构体类型变量在程序执行期间,( )。 查看答案
单选题 下列选项不符合良好程序设计风格的是( )。 查看答案
单选题 有以下程序
#include
main()
{int y=9;
for(;y>0;y--)
if(y%3==0)printf("%d",--y);
}
程序的运行结果是( )。
查看答案
单选题 面向对象的设计方法与传统的面向过程的方法有本质不同,它的基本原理是( )。 查看答案
单选题 以下程序的输出结果是( )。
main( )
{ int i,a[4] [4]一{{1,3,5),{2,4,6},{3,5,7}};
printf("%(1%d%d%d\n".a[O][3],a[1][2],a[2]
[1],a[3][0];
}
查看答案
单选题 若执行以下程序时从键盘上输入9,则输出结果是( )。
main( )
{ int n;
scanf(”%d”,&n);
if(n++<10)printf(”/%d\n”,n);
else printf(”%d\n”,n--);
}
查看答案