求助,无法输出结果,编译可以过
#include <stdio.h>#include <stdlib.h>
#include<string.h>
char **readWords(int n)
{
int i;
char *a=malloc(n*sizeof(int));
char **b=malloc(n*sizeof(*a));
for(i=0;i<n;i++){
scanf("%d",&*(a+i));
}
for(i=0;i<n;i++){
*(b+i)=a+i;
}
return b;
}
void sort(char **ptr, int size,int *minlenPtr,int *maxlenPtr)
{
int i,j,len=0,maxlen=0,minlen=0;
char temp;
for (j=0;j<size;j++){
for(i=0;i<size-j;i++)
{
if(strlen(*(ptr+i))<strlen(*(ptr+j)))
{
temp=**(ptr+i);
**(ptr+i)=**(ptr+j);
**(ptr+j)=temp;
}
while(**ptr=getchar()!='n'){
len++;
if(len>maxlen){
maxlen=len;
*maxlenPtr=maxlen;
}
if(len<minlen){
minlen=len;
*minlenPtr=minlen;
}
}
}
}
printf("Min length is %d and max length is %d",minlen,maxlen);
}
void output(char **ptr,int size)
{
int i;
for(i=0;i<size;i++){
printf("%c",**(ptr+i));
}
}
void freeMemory(char **ptr,int size)
{
free(readWords(size));
ptr=NULL;
}
main()
{
char *ptr=0;
int n;
int *minlenPtr;
int *maxlenPtr;
printf("Please input the number of words:");
scanf("%d",&n);
getchar();
printf("Please input the words:n");
readWords(n);
sort(&ptr,n,minlenPtr,maxlenPtr);
output(&ptr,n);
freeMemory(&ptr,n);
system("pause");
}