标签:strlen ret find 分享 是什么 [] color rac with
#include<stdio.h> #include<string.h> //要用strstr()函数来查找字符串 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; for(i=0;i<5;i++){ if(strstr(tracks[i],search_for)) //显示所有匹配的歌曲 printf("Track %i:‘%s‘\n",i,tracks[i]); } } int main() { char search_for[80]; printf("Search for:"); //输入查找的关键字 fgets(search_for,80,stdin); search_for[strlen(search_for)-1]=‘\0‘; find_track(search_for); //显示匹配的歌曲 return 0; }
运行结果:
要点
问题
标签:strlen ret find 分享 是什么 [] color rac with
原文地址:http://www.cnblogs.com/OctoptusLian/p/6623477.html