头疼!不知道哪错了,帮忙看看。
#include<stdio.h>#include<string.h>
#include<ctype.h>
void origin(char **p,int n);
void ascii(char **p,int n);
void length(char **p,int n);
void word(char **p,int n);
int first_word(char *p);
int main()
{
char str[10][81];
char *p[10];
char command[10];
int n;
while(1)
{
n=0;
puts("input no more than 10 strings finished by EOF(^Z):");
do
{
if(gets(str[n])==NULL)
break;
p[n]=str[n];
n++;
} while(n<10);
puts("select:"); //选择
puts("a.put originally");
puts("b.put in order of ascii");
puts("c.put in order of string's length");
puts("d.put in order of first word's length");
puts("e.input strings again");
puts("q.quit");
do
{
gets(command);
switch(command[0])
{
case 'a': origin(p,n);break;
case 'b': ascii(p,n);break;
case 'c': length(p,n);break;
case 'd': word(p,n); break;
case 'e':break;
default: puts("Quit");return 0;
}
}
while(command[0]!='e');
}
}
void origin(char **p,int n)
{
int i;
for(i=0;i<n;i++)
puts(p[i]);
}
void ascii(char **p,int n)
{
int i,j;
char *temp;
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(strcmp(p[j],p[j+1])>0)
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
origin(p,n);
}
void length(char **P,int n)
{
int i,j;
char *temp;
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if( strlen(p[j]) > strlen(p[j+1]) )
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
origin(p,n);
}
int first_word(char *p)
{
int i=0;
for(;!isalpha(*p);p++)
if(*p=='\0')
return 0;
for(i=1;isalpha(p[i]);i++)
continue;
return i;
}
void word(char **p,int n)
{
int i,j;
char *temp;
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(first_word(p[j])>first_word(p[j+1]))
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
origin(p,n);
}