#define alen(x) ((sizeof x)/(sizeof *x))
typedef struct {
char *movie_title;
int minutes;
float price;
} DVD;
int
main()
{
DVD movies[10] = {
{ "The Dark Knight", 153, 14.99},
{ "Iron Man", 126, 12.99},
{ "Batman Begins", 141, 9.99},
{ "Batman Returns", 126, 9.99},
{ "Teenage Mutant Ninja Turtles", 87, 7.99},
{ "The Incredible Hulk", 114, 12.99},
{ "X-Men", 104, 12.99},
{ "Spider-Man", 121, 14.99},
{ "Fantastic Four", 106, 14.99},
{ "Captain America", 124, 19.99},
};
qsort(movies, alen(movies), sizeof *movies, tcomp);
printf("Movies sorted: \n");
for (int i = 0; i < alen(movies); i++)
printf("%s\n", movies[i].movie_title);
}
int
tcomp (const void * a, const void * b)
{
return strcmp(((DVD*)a)->movie_title,((DVD*)b)->movie_title);
}
當使用函數tcomp和qsort對電影標題進行排序時,我需要忘記電影標題中的「A」,「An」和「The」。有人能幫我弄清楚如何以優雅的方式做到這一點?在C中使用qsort()並跳過特定字符集
比較之前剝離... –