包括
main()
{
int n;
int i;
char tempMonth[255]; //Used to store the month until checked
scanf("%d", &n);
struct date *list;
list = (struct date *)malloc((n * sizeof(struct date)));
for(i = 0; i < n; i++)
{
scanf("%s %d %d", tempMonth, &list[i].day, &list[i].year);
list[i].month = getMonth(tempMonth);
}
convertFullYear(list, n);
qsort(list, n, sizeof(struct date), (compfn)sortDates);
convertSmallYear(list, n);
for(i = 0; i < n; i++)
{
printf("%s %d %02d\n", months[list[i].month], list[i].day, list[i].year);
}
char *pos = (char*) bsearch(Jan, list, sizeof(list), sizeof(Jan), findJan);
}
正如你可以看到我已經把我的想法是正確的調用bsearch,但是如果這是正確的我不知道在哪裏可以從這裏走。
注意:你應該重寫'getMonth'作爲循環。 – 2012-03-09 13:09:32
是的,一旦我得到它充分運作我會這樣做,只是保持它,因爲它現在的作品 – Mike 2012-03-09 13:11:02
'int Jan = 0100;'請注意,這是一個八進制常數。 Jan將是64位十進制(這是無效的) – wildplasser 2012-03-09 13:28:58