gcc,帮我看看错在哪里了,编译提示:段错误 ( 积分: 100 )

  • 主题发起人 主题发起人 老迟
  • 开始时间 开始时间

老迟

Unregistered / Unconfirmed
GUEST, unregistred user!
#include<string.h>
#include<stdio.h>
main(int argc,char *argv){
char *a[20]={"Good","Bad","hat","cat","cap","thin","fat","big","tiny","Chi","X
ian","mine","tree","row","new","add","base","dog","egg","spy"};
int i,t;
char f[]={"-f"},s[]={"-s"},r[]={"-r"};
for(i=1;i<argc;i++){
if(strcmp(argv,f)==0)f1(a);
else
if(strcmp(argv,r)==0)f2(a);
else
if(strcmp(argv,s)>0){
t=strcmp(*(argv+i),s)-48;
f3(a,t);
}
}
for(i=0;i<20;i++)
printf("%s/n",a);
}
f1(char *a[20]){
int i,j,k;
char *temp;
for(i=0;i<19;i++){
k=i;
for(j=i+1;j<20;j++)
if(strcmp(a[k],a[j])>0)k=j;
if(k!=i)
{temp=a;
a=a[k];
a[k]=temp;}
}
}要求:扩展排序程序,接受命令行参数,待排序字符集(〉20)事先设定,用二维数组储存
,排序算法自定。-f忽略大小写,-r逆序排序-s指定排序起始字符如-s2
 
#include<string.h>
#include<stdio.h>
main(int argc,char *argv){
char *a[20]={"Good","Bad","hat","cat","cap","thin","fat","big","tiny","Chi","X
ian","mine","tree","row","new","add","base","dog","egg","spy"};
int i,t;
char f[]={"-f"},s[]={"-s"},r[]={"-r"};
for(i=1;i<argc;i++){
if(strcmp(argv,f)==0)f1(a);
else
if(strcmp(argv,r)==0)f2(a);
else
if(strcmp(argv,s)>0){
t=strcmp(*(argv+i),s)-48;
f3(a,t);
}
}
for(i=0;i<20;i++)
printf("%s/n",a);
}
f1(char *a[20]){
int i,j,k;
char *temp;
for(i=0;i<19;i++){
k=i;
for(j=i+1;j<20;j++)
if(strcmp(a[k],a[j])>0)k=j;
if(k!=i)
{temp=a;
a=a[k];
a[k]=temp;}
}
}要求:扩展排序程序,接受命令行参数,待排序字符集(〉20)事先设定,用二维数组储存
,排序算法自定。-f忽略大小写,-r逆序排序-s指定排序起始字符如-s2
 
上面程序编译了一下
除了没有f2,f3的函数定义之外没什么错误啊
 
就这样吧。
 

Similar threads

I
回复
0
查看
742
import
I
I
回复
0
查看
1K
import
I
I
回复
0
查看
830
import
I
I
回复
0
查看
640
import
I
后退
顶部