I went through some exercises from the book Head First C. And there is one jukeBox program.
The source is here:
#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; }
I use the terminal to compile and view the output of a program with gcc version 4.8.2, for example:
gcc pr.c -o pr
And whenever I try to run a program and enter a search string, I get no output. The program simply terminates and terminates.
I also want to mention that I tried to compile this code on ideone.com here .
What problems can be? The terminal does not display output at all.
source share