【发布时间】:2016-10-03 20:19:11
【问题描述】:
我正在尝试搜索轨道数组中是否有可用的轨道。当我给出任何输入时,strstr() 函数总是返回 false。如果我使用 else 块,则每次执行 else 块。
char tracks[][80] = {
"I left my heart in Harvard Med School",
"Newark, Newark - a wonderful town",
"Dancing with a Dork",
"From here to maternity",
"The girl from Iwo Jima",
};
// function to search the track with entered search string //
void find_track(char search_for[]) {
int i;
for (i = 0; i < 5; i++) {
/** this if condition is returning false every time */
if (strstr(tracks[i], search_for)){
printf("Track %i: '%s'\n", i, tracks[i]);
}/**else{
printf("some thing went wrong @ %i\n", i);
}**/
}
}
int main() {
char search_for[80];
printf("Search for: ");
fgets(search_for, 80, stdin);
find_track(search_for);
return 0;
}
输入:
gcc test.c -o test && test
搜索:with
预期结果:Track 2:'Dancing with a Dork'
请帮帮我。
【问题讨论】:
-
单步调试器。