指针在结构体中引用出错 char *[],请各路大神指点!
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
bool str_in(char **);
void str_sort(const char *[],int);
void swap(void **p1,void **p2);
void str_out(char *[],int);
const size_t BUFFER_LEN=256;
const size_t NUM_P=50;
int main(void)
{
char *pS[NUM_P];
int count=0;
printf("\nEnter successive lines,pressing Enter at the end of" "each line.\nJust press Enter to end.\n");
for(count=0;count<NUM_P;count++)
if(!str_in(&pS[count]))
break;
str_sort( pS,count); 请指正这句出错原因 invalid conversion from `char**' to `const char**'
str_out( pS,count);
system("pause");
return 0;
}
bool str_in(char **pString)
{
char buffer[BUFFER_LEN];
if(gets(buffer)==NULL)
{
printf("\nError reading string.\n");
exit(1);
}
if(buffer[0]='\0')
return false;
*pString=(char*)malloc(strlen(buffer)+1);
if(*pString==NULL)
{
printf("\nOut of menory.");
exit(1);
}
strcpy(*pString,buffer);
return true;
}
void str_sort(const char *p[],int n)
{
char *pTemp=NULL;
bool sorted=false;
while(!sorted)
{
sorted=true;
int i=0;
for(i=0;i<n-1;i++)
if(strcmp(p[i],p[i+1])>0)
{
sorted=false;
swap(&p[i],&p[i+1]);//指向常量的指针只可以交换地址改变变量值,这句正确但是DEVC报错 invalid conversion from `char**' to `void**' initializing argument 1 of `void swap(void**, void**)'
}
}
}
void swap(void **p1,void **p2)
{
void *pt=*p1;
*p1=*p2;
*p2=pt;
}
void str_out(char *p[],int n)
{
printf("\nYour input sorted in older is :\n\n");
int i=0;
for(i=0;i<n;i++)
{
printf("%s",p[i]);
free(p[i]);
p[i]=NULL;
}
return;
}
已附上代码及DEVC报错提示。








