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