#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”。有人可以帮我弄清楚如何以优雅的方式做到这一点吗?