strstr()函数问题
不知道下面注释的地方理解是否正确?——请教了char match[256], entry[256];
FILE *titles_fp;
int count = 0;
char *found, *title, *catalog;
mvprintw(10, 0, "Enter a string to search for in CD titles: ");
get_string(match); //输入如:myCD1
titles_fp = fopen(title_file, "r"); //文件中存放形式如: cd11,myCD1,liuxing ,zhoujielun
// cd22,myCD2,gudian ,shubote
if (titles_fp) {
while (fgets(entry, 256, titles_fp)) {
catalog = entry;
if (found == strstr(catalog, ",")) {
//上面是在字符串catalog中查找首次出现的 字符串“,”的位置,并返回该位置的指针
*found = '\0'; //这里是将原来存放‘,’的位置改为‘\0’吗?为什么这样做?
title = found + 1; //则此处 title=“myCD1,liuxing ,zhoujielun”吗?
if (found == strstr(title, ",")) {
*found = '\0';
if (found == strstr(title, match)) {
count++;
strcpy(current_cd, title);
strcpy(current_cat, catalog);
}
}
}
}
fclose(titles_fp);