关于《Head First C》上面的一道例题的疑问
最近在学习Head First C这本书,看到strstr()那部分的例题,一道在字符串数组里面查找字符串的题目,上机实现了一下,发现有问题,程序没报错,但没有正确的运行。无论如何也找不到出现问题的原因,希望大家能帮忙一下。
#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; 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); find_track(search_for); return 0;}The fgets function reads a string from the input stream argument and stores it in string. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first. The result stored in string is appended with a null character. The newline character, if read, is included in the string. fgetws is a wide-character version of fgets. fgetws reads the wide-character argument string as a multibyte-character string or a wide-character string according to whether stream is opened in text mode or binary mode, respectively. For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes.