下列给定程序中函数fun的功能是:用冒泡法埘6个字符串按m4,到大的顺序进行排序。 请改止程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdli

admin2021-04-28  19

问题 下列给定程序中函数fun的功能是:用冒泡法埘6个字符串按m4,到大的顺序进行排序。
    请改止程序中的错误,使它能得出正确的结果。
    注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题程序:
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#define MAXLINE 20
fun(char*pstr[6])
{
    int i,j;
    char*P;
    for(i=0,i<5;i++)
    {
/**********found***********/
    for(j=i+1,j<6,j++)
    {
    if(strcmp(*(pstr+i),(pstr+
j))>0)
    {
    P=*(pstr+i);
/**********found***********/
    *(pstr+i)=pstr+j;
    *(pstr+j)=P;
    }
    }
    }
}
void main()
{
    int i;
    char*pstr[6],str[6][MAXLINE];
    system(“CLS”);
    for(i=0;i<6;i++)
    pstr=str
    printf(“\nEnter 6 string(1
string at each line):\n”);
    for(i=0;i<6;i++)
    scanf(“%S”,pstr);
    fun(pstr);
    printf(“The strings after sorring:\n”),
    for(i=0;i<6;i++)
    printf(“%s\n”,pstr);
}

选项

答案(1)for(j=i+1;j<6;j++) (2)*(pstr+i)=*(pstr+j);

解析 (1)此处考查for语句的格式,各表达式之间应用“;”隔开。
  (2)此处考查用指针表示数组元素的方法,*(pstr+i)表示pstr所指向数组的第i个元素,同理*(pstr+j)表示pstr所指向数组的第j个元素。
转载请注明原文地址:https://kaotiyun.com/show/zRtp777K
0

最新回复(0)