以下是相应的代码:问题解决了,确实是因为我的判断语句之后多了一个分号,所以每次if判断都进入;另外我觉得这里应该是用赋值=语句才对,可能是作者疏忽吧。。
谢谢大家帮忙!
void find_cd()
{
char match[MAX_STRING], entry[MAX_ENTRY];
FILE *titles_fp;
int count = 0;
char *found, *title, *catalog;
mvprintw(Q_LINE, 0, "Enter a string to search for in CD titles: ");
get_string(match);
titles_fp = fopen(title_file, "r");
if (titles_fp) {
while (fgets(entry, MAX_ENTRY, titles_fp)) {
catalog = entry;
if (found == strstr(catalog, ",")); {
*found = '\0';
title = found + 1;
if (found == strstr(title, ",")) {
*found = '\0';
if (found == strstr(title, match)) {
count++;
strcpy(current_cd, title);
strcpy(current_cat, catalog);
}
}
}
}
fclose(titles_fp);
}
if (count != 1) {
if (count == 0) {
mvprintw(ERROR_LINE, 0, "Sorry, no matching CD found. ");
}
if (count > 1) {
mvprintw(ERROR_LINE, 0, "Sorry, match is ambiguous: %d CDs found. ",count);
}
current_cd[0] = '\0';
get_return();
}
}