错误-C程序使用指针对数组中的名称进行排序

错误-C程序使用指针对数组中的名称进行排序,c,pointers,C,Pointers,我正试图编写一个小型c程序来读取名称数组,并使用指针根据字母顺序对它们进行排序 有人能看一下这个代码并验证一下吗 代码 #include<stdio.h> #include<string.h> #include<string.h> void sort char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*); int main(){ char a[10],

我正试图编写一个小型c程序来读取名称数组,并使用指针根据字母顺序对它们进行排序

有人能看一下这个代码并验证一下吗

代码

#include<stdio.h>
#include<string.h>
#include<string.h>
void sort char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*);
int main(){
    char a[10],[20];
    int n,i;
    printf("Enter How Many Numbers you want:");
    scanf("%d",&n);
    void swap(char*,char*);
    printf("Enter strings:");
    fflush(n);
    for(i=0;i<n;i++)
    puts(a[i]);
}   
void sort char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*){
    int i,j;
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
            if(*p)(a[i],a[j]>0)
                (*q)[a(i),a(j)];
            return;

}
void swap(char *s1, char *s2){
    char t[20];
    strcpy(t,s1);
    strcpy(s1,s2);
    strcpy(s2,t);
    return;
}   
1#包括
2#包括
3#包括
4 void排序字符a[][20],int n,int(*p)(常量字符*,常量字符*),void(*q)(字符*字符*);
//        ^^^^ 
//[错误]第4行:错误:“char”之前应为初始值设定项
//编译器询问“sort”为什么在这里。
//也许这行缺少括号?改为:
//void排序(字符a[][20],int n,int(*p)(常量字符*,常量字符*),void(*q)(字符*字符*);
5 int main(){
6个字符a[10],[20];
//                ^   
//[错误]第6行:错误:在“[”标记之前应为非限定id
//编译器对逗号感到困惑。
//也许应该删除逗号?
7 int n,i;
8 printf(“输入您想要的数字:”);
9扫描频率(“%d”和“n”);
10无效掉期(字符*,字符*);
11 printf(“输入字符串:”);
12(n);
//             ^ 
//[错误]第12行:错误:从“int”到“FILE*”的转换无效
//[错误]第12行:错误:初始化“int-fflush(FILE*)”的参数1
//fflush(n)可能没有做预期的事情。
//也许应该删除该行?

13 for(i=0;iYou可能想注销并重新阅读您最喜欢的C初级读本。排序似乎需要一些()。欢迎使用堆栈溢出。请尽快阅读此页。您的
sort
的“函数声明”缺少开括号和闭括号-
void sort(char…)
。这就把其他一切都抛在脑后了。您的“函数定义”也有同样的问题。您还需要了解如何声明多维数组(C在数组中不使用逗号)。在开始使用函数指针之前,您需要掌握一些类似的基础知识。
[Error] line4: error: expected initializer before "char"
[Error] line6: error: expected unqualified-id before '[' token
[Error] line12: error: invalid conversion from `int' to `FILE*'
[Error] line12: error:   initializing argument 1 of `int fflush(FILE*)'
[Error] line14: error: invalid conversion from `char' to `const char*'
[Error] line14: error:   initializing argument 1 of `int puts(const char*)'
[Error] line16: error: expected initializer before "char"
[Warning] line31:5: warning: no newline at end of file

Complete Make Untitled19: 7 error(s), 1 warning(s)
1    #include<stdio.h>
2    #include<string.h>
3    #include<string.h>
4    void sort char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*);
//        ^^^^ 
//[Error] line4: error: expected initializer before "char"
//The compiler questions why 'sort' is here. 
//Perhaps the line is missing parenthesis? Change to: 
//   void sort(char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*));

5   int main(){
6       char a[10],[20];
//                ^   
//[Error] line6: error: expected unqualified-id before '[' token
//The compiler is confused about the comma.  
//Perhaps the comma should be removed?

7       int n,i;
8       printf("Enter How Many Numbers you want:");
9       scanf("%d",&n);
10      void swap(char*,char*);
11      printf("Enter strings:");
12      fflush(n);
//             ^ 
//[Error] line12: error: invalid conversion from `int' to `FILE*'
//[Error] line12: error: initializing argument 1 of `int fflush(FILE*)'
//fflush(n) probably is not doing what was intended.  
//Perhaps the line should be removed?

13      for(i=0;i<n;i++)
14          puts(a[i]);
//               ^^^^  
//[Error] line14: error: invalid conversion from `char' to `const char*'
//[Error] line14: error:   initializing argument 1 of `int puts(const char*)'
//These errors are a result of the comma on line #6.

15      }   
16      void sort char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*){
//           ^^^^ 
//[Error] line16: error: expected initializer before "char"
//The compiler questions why 'sort' is here. 
//Perhaps the line is missing parenthesis? Change to: 
//   void sort(char a[][20], int n, int (*p)(const char*, const char*),void(*q)(char* char*))

17      int i,j;
18      for(i=0;i<n-1;i++)
19          for(j=i+1;j<n;j++)
20              if(*p)(a[i],a[j]>0)
21                  (*q)[a(i),a(j)];
22              return;
23  }
24
25  void swap(char *s1, char *s2){
26      char t[20];
27      strcpy(t,s1);
28      strcpy(s1,s2);
29      strcpy(s2,t);
30      return;
31  }   
//[Warning] line31:5: warning: no newline at end of file    
// Your compiler likes to have an extra blank line at the end of the file.
// It is unhappy to find the blank line missing.
// Add one (or more) blank lines to the end of the file to eliminate warning.