title: C: String search in txt file and output
body: <p>For my university project, I have to write a C program called &quot;jukebox&quot; that lets the user put in a file name, a search string, and then displays every line of the text file containing that search string.</p>
  <p>Every line (98 in total) contains &quot;<em>artist name - song name</em>&quot;. The output shall be &quot;<em>track number - artist name - song name</em>&quot;</p>
  <p>I have already searched and found some snippets of information but I cannot seem to make sense out of it and it seems as if I do not understand C well enough to apply that to my problem, therefore this is my last hope to find help.</p>
  <p>I would like to know: what have I done wrong, how exactly to use <em>strstr</em> and <em>getline</em> and what to put in it, and how to printf the found information correctly.
  Another problem I encounter is missing every first letter when printing the whole text file (accidentally).</p>
  <p>My code so far is:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char fileName[60]; // per definition Jukebox.txt
  char searchString[60];
  char textinfo[60]; // contains artist and song name
  
  // maximum of letters per line is 60
  
  int temp;
  int i = 1;
  int x = 0;
  size_t result = 100;
  
  FILE *pFile;
  
  int main(void) {
  
      printf(&quot;Please enter file name: &quot;);
      scanf(&quot;%s&quot;, fileName);
  
  
      pFile = fopen(&quot;Jukebox.txt&quot;, &quot;r&quot;);
  
  
      if (pFile == NULL) {
          printf(&quot;File could not be opened!\n&quot;);
      }
      else {
  
          printf(&quot;Please enter search string: &quot;);
          scanf(&quot;%s&quot;, searchString);
  
  
          textinfo = strstr(  );
  
  
          printf(&quot;%s\n&quot;, textinfo);
  
          for(i = 0; x &lt; 1; i++) {
  
              char *p = textinfo;
  
              getline(&amp;p, &amp;list, pFile);
  
              printf(&quot;%d: %s&quot;, i , textinfo);
  
  
              if((temp = fgetc(pFile)) == EOF) {
                  x = 2;
              }
          }
      }
  
      return 0;
  
  }
  </code></pre>