用qsort对字符串结构体进行排序为什么会出错,大家帮忙修改下
程序代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> struct str { char s[20]; }st[200]; int cmp(const void *a, const void *b) { return strcmp((*(str *)a).s,(*(str *)b).s); } int main() { int n,i; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { scanf("%s",st[i].s); } qsort(st,n,sizeof(st[0].s),cmp); for(i=0;i<n;i++) { printf("%s\n",st[i].s); } } return 0; }
||warning: command line option "-Weffc++" is valid for C++/ObjC++ but not for C|
\c\main.c||In function 'cmp':|
\c\main.c|10|error: 'str' undeclared (first use in this function)|
\c\main.c|10|error: (Each undeclared identifier is reported only once|
\c\main.c|10|error: for each function it appears in.)|
\c\main.c|10|error: expected expression before ')' token|
\c\main.c|10|error: expected expression before ')' token|
||=== Build finished: 5 errors, 1 warnings ===|