I decided that this summer would be a good time to study C. In the book that I'm reading, there was this small program:
#include <stdio.h>
#include <string.h>
char tracks[][80] = { //a list of songs that the user can search through
"I left my heart in Harvard Med School",
"Newark, Newark - a wonderful town",
"Dancing with a dork",
"From here to maternity",
"The girl form Iwo Jima",
};
void find_track(char search_for[]){
int i;
for (i = 0; i < 5; i++){ //loop through our array
if (strstr(tracks[i], search_for)) //check if the user's search term is in this string
printf("Track %i: '%s'\n", i, tracks[i]); //if so, the print the track number and title
}
}
int main()
{
char search_for[80];
printf("Search for: ");
fgets(search_for, 80, stdin); //get user input
find_track(search_for); //send user input to the function
return 0;
}
This code compiles fine under TinyCore Linux 4.5.3 and under cygwin + windows xp. Unfortunately, It doesn't run correctly under either of them. This is very annoying, even if it is a first edition book.
My guess is that it has something to do with "pointer decay".
Does anyone have any idea what is causing this odd bug?
(I realize that this isn't really related to Core and no one has any obligation to offer any help of any sort
)