一起答
主观

下列给定的程序中,函数proc的功能是:判断字符ch 是,与str所指字符串中的某个字符相同;若相同,则什么也不做,若不同,则将其插在串的最后。请修改程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

#include

#include

//****found****

void proc(char str,char ch)

{

while(*str &&*str!=ch)str++;

//****found****

if(*str==ch)

{ str[0]=ch;

//****found****

str[1]='0':

}

}

void main

{

char str[81],ch;

system("CLS");

printf("\nPlease enter a string:");

gets(str);

printf("\n Please enter the character to

search:");

ch=getchar;

proc(str,ch);

printf("\nThe result is%s\n",str);

}

参考答案
查看试卷详情
相关试题
  1. 学生的记录由学号和成绩组成,M名学生的数据已在主函数中放人结构体数组stu中,请编写函数proc,它的功能是:把指定分数范围之外的学生数据放在b所指的数组中,分数范围之外的学生人数由函数值返回。

    例如,输入的分数是70和79,则应当把分数低于70和高于79的学生数据输出,不包含70分和79分的学生数据。主函数中把70放在low中,把79放在heigh中。

    注意:部分源程序给出如下。

    请勿改动main函数和其他函数中的任何内容,仅在函数proc的花括号中填人所编写的若干语句。

    试题程序:

    #include

    #define M 16

    typedef struct

    {

    char num[10];

    int s:

    }

    STREC;

    int proc(STREC*a,STREC*b,int i,int h)

    {

    }

    void main

    {

    STREC stu[M]={{"GA005",55),{"GA003",96},

    {"GA002",80),{"GA004",68),

    {"GA001",88},{"GA007",74},

    {"GA008",85),{"GA006",89},

    {"GA015",90),{"GA013”,53),

    {"GA012",66},{"GA014”,82),

    {"GA011",73},{"GA017",69),

    {"GA018",64),{"GA016",86}};

    STREC h[M];

    int i,n,low,heigh,t;

    printf("Enter 2 integer number low&

    heigh:");

    scanf("%d%d",&low,&heigh);

    if(heigh

    {

    t=heigh:

    heigh=low;

    low=t;

    }

    n=proc(stu,h,low,heigh);

    printf("The student’S data out

    %d--%d:\n",low,heigh);

    for(i=0;i

    printf("%S%4d\n",h[i].num,h[i].s);

    //输出指定分数范围外的学生记录

    printf("\n");

    }

  2. 下列给定的程序中,函数proc的功能是:判断字符ch 是,与str所指字符串中的某个字符相同;若相同,则什么也不做,若不同,则将其插在串的最后。请修改程序中的错误,使它能得出正确的结果。

    注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

    试题程序:

    #include

    #include

    #include

    #include

    //****found****

    void proc(char str,char ch)

    {

    while(*str &&*str!=ch)str++;

    //****found****

    if(*str==ch)

    { str[0]=ch;

    //****found****

    str[1]='0':

    }

    }

    void main

    {

    char str[81],ch;

    system("CLS");

    printf("\nPlease enter a string:");

    gets(str);

    printf("\n Please enter the character to

    search:");

    ch=getchar;

    proc(str,ch);

    printf("\nThe result is%s\n",str);

    }

  3. str是一个由数字和字母字符组成的字符串,由变量num传入字符串长度。请补充函数proc,该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。

    例如,str="abc3de987f9621",结果为:3987621。

    注意:部分源程序给出如下。

    请勿改动main函数和其他函数中的任何内容,仅在函数proc的横线上填入所编写的若干表达式或语句。

    试题程序:

    #include

    #define M 80

    int bb[M];

    int proc(char str[],int bb[],int num)

    {

    int i,n=0;

    for(i=0;i

    {

    if(【1】)

    {

    bb[n]=【2】:

    n++:

    }

    }

    return 【3】 ;

    }

    void main

    {

    char str[M];

    int mum=0,n,i;

    printf("Enter a strin9:\n");

    gets(str);

    while(str[num])

    num++:

    n=proc(str,bb,num);

    printf("\nbb=");

    for(i=0;i

    printf("%d",bb[i]);

    }

  4. 有以下程序:

    #include<

    struct stu { int num;char name[10];int age;} 

    void fun(struct stu*p) 

    { printf("%s\n",(*p).name);} 

    main 

    { struct stu students[3]={{9801,"Zhang".20}, {9802,"Wang",19},{9803,"Zhao",1 8}} 

     fun(students+2); } 

    输出的结果是(  )。

    • A.Zhang
    • B.Zhao
    • C.Wang
    • D.18
  5. 下列程序执行后的输出结果是(  )。 

    main 

    { int x='f';

     printf("%c\n",'A'+(x-'a'+1));

    }

    • A.G
    • B.H
    • C.I
    • D.J
  6. 若有定义:“int a[2][3];”,则对a数组的第i行第j 列元素的正确引用为( )。

    • A.*(*(a+i)+j)
    • B.(a+i)[j]
    • C.*(a+i+j)
    • D.*(a+i)+j
  7. 有以下程序 

    #include

    main 

    { FILE *fp;

     int a[10]={1,2,3,0,0},i; 

     fp=fopen("d2.dat,"wb"); 

     fwrite(a,sizeof(int),5,fp); 

     fwrite(a,sizeof(int),5,fp); 

     fclose(fp); 

     fp=fopen("d2.dat","rb"); 

     fread(a.sizeof(int),10,fp); 

     fclose(fp); 

     for(i=0;i<10;i++) printft("%d",a[i]);

    程序的运行结果是( )。

    • A.1,2,3,0,0,0,0,0,0,0,
    • B.1,2,3,1,2,3,0,0,0,0,
    • C.123,0,0,0,0,123,0,0,0,0,
    • D.1,2,3,0,0,1,2,3,0,0,
  8. 有下列程序: 

    main 

    { int k=5;

     while(--k)

      printf("%d",k=1); 

     printf("\n"); } 

    执行后的输出结果是( )。

    • A.1
    • B.2
    • C.4
    • D.死循环
  9. 下列程序执行后的输出结果是(  )。 

    main 

    { int a[3][3],*p,i; 

     p=&a[0][0]; 

     for(i=0;i<9;i++) p[i]=i+1; 

     printf("%d\n",a[1][2]);}

    • A.3
    • B.6
    • C.9
    • D.随机数
  10. 表达式“~0x11”的值是(  )。

    • A.0xFFEE
    • B.0x71
    • C.0x0071
    • D.0xFFF1