我已经创建了一个结构数组,并且我想使用qsort对它们进行排序以按字母顺序排序日期到字符串月份或我应该说char月份[]。我怎么能使下面的代码显示一个月的结构。请指教。感谢如何在C编程中使用qsort对结构进行排序
struct dates
{
int index;
int day;
int year;
char month[15];
};
int i=0;
int count = 0 ;
char test ='\0';
int total =0;
printf("Please enter the number of dates you need to display");
scanf("%d",&total);
struct dates *ip[total];
for(count =0; count< total; count++){
ip[count] = (struct dates*)malloc(sizeof(struct dates));
printf("\nEnter the name month.");
scanf("%s", ip[count]->month);
printf("\nEnter the Day.");
scanf("%d",&ip[count]->day);
printf("\nEnter the Year.");
scanf("%d", &ip[count]->year);
}
for(i=0; i<total; i++){
printf("%s %d %d\n\n",ip[i]->month,ip[i]->day,ip[i]->year);
}
你有没有看'人qsort'?文档解释了你需要做的事情,并举例说明如何使用它。 – 2012-03-22 17:40:07