[求助]Delaration syntax error
有三个错误两个警告1,Delaration syntax error
2,undefined symbol i,j,k.
warning
'temp'is assignde a value that is never used
'n'is never used
将若干字符串按字母顺序(由小到大)输出。
代码如下:
#include <stdio.h>
#include <string.h>
void main()
{void sort(char *name[],int n);
void print(char *name[],int n);
char *name[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
int n=5;
sort(name,n);
print(name,n);
}
void sort(char *name[],int n)
{char *temp
int i,j,k;
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(strcmp(name[k],name[j])>0) k=j;
if(k!=i)
{temp=name;name=name[k];name[k]=temp;}
}
}
void print(char *name[],int n)
{int i;
for(i=0;i<n;i++)
printf("%s\n",name);
}
代码如下:
#include <stdio.h>
#include <string.h>
void main()
{void sort(char *name[],int n);
void print(char *name[],int n);
char *name[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
int n=5;
sort(name,n);
print(name,n);
}
void sort(char *name[],int n)
{char *temp
int i,j,k;
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(strcmp(name[k],name[j])>0) k=j;
if(k!=i)
{temp=name;name=name[k];name[k]=temp;}
}
}
void print(char *name[],int n)
{int i;
for(i=0;i<n;i++)
printf("%s\n",name);
}