运行程序时显示未响应~~求大神指教~~
运行程序时显示未响应~~求大神指教~~编译器是codeblocks#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
char *str_in(void);
void str_sort(const char *[],int);
void swap(void **p1,void **p2);
void str_out(char *[],int);
#define BUFFER_LEN 256
#define 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((pS[count]=str_in())==NULL)
break;
str_sort(pS,count);
str_out(pS,count);
return 0;
}
char *str_in(void)
{
char buffer[BUFFER_LEN];
char *pString=NULL;
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 memory.");
exit(1);
}
return strcpy(pString,buffer);
}
void str_sort(const char *p[],int n)
{
char *pTemp=NULL;
bool sorted=false;
while(!sorted)
{
sorted=true;
for(int i=0;i<n-1;i++)
if(strcmp(p[i],p[i+1])>0)
{
sorted=false;
swap(&p[i],&p[i+1]);
}
}
}
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 order is:\n\n");
for(int i=0;i<n;i++)
{
printf("%s\n",*p);
free(*p);
*p++=NULL;
}
return;
}