【发布时间】:2016-10-20 01:18:22
【问题描述】:
我正在制作一个程序,通过从用户那里获取输入字符串来从曲目列表中搜索曲目。
#include<stdio.h>
#include<string.h>
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",
};
void find_track(char search_for[])
{
int i, m = 0;
for(i = 0; i<5; i++)
{
控件到达这行代码
m = strstr(tracks[i], search_for);
if(m)
{
printf("Track%i : '%s' \n", i, tracks[i]);
}
}
}
strstr() 返回 0
int main()
{
char search_for[80];
printf("Search for : ");
fflush(stdin);
fgets(search_for, 80, stdin);
find_track(search_for);
return 0 ;
}
【问题讨论】:
-
它在
search_for中包含一个换行符。
标签: c string codeblocks strstr