title: Read text file, then store lines in array to filter out certain strings
body: <p>I'm currently trying to read a text file, and store the lines in an array. I then try to filter out certain words with strstr. I'm getting no output when trying to print elements of the array, and the strstr function doesn't seem to work. Visual Studio is telling me that I'm using uninitialized memory in my lines pointer. Any help is greatly appreciated.</p>
  <p>Format of the text file:</p>
  <pre><code>// comments should be ignored
   
  //empty lines as well
  &lt;Name&gt;Peter&lt;/Name&gt;
  &lt;Name&gt;Anna&lt;/Name&gt;
  &lt;Age&gt;16&lt;/Age&gt;
  &lt;Pet&gt;
  &lt;Race&gt;Dog&lt;/Race&gt;
  &lt;PetName&gt;Lucky&lt;/Petname&gt;
  &lt;/Pet&gt;
  </code></pre>
  <p>This is my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
      char* c = &quot;test1.txt&quot;;
      char s[500];
  
      char* lines[100];
      int sizelines = 0;
  
      printf(&quot;%s \n\n&quot;, c);
  
      FILE* myFile = NULL;
      myFile = fopen(c, &quot;r&quot;);
  
      if (myFile != NULL) 
      {
          while (fgets(s, 500, myFile) != NULL) 
          {
              if (s[0] == '/') continue; // ignore lines that start with /
              if (s[0] == ' ') continue; // ignore lines that start with &quot; &quot;
              lines[sizelines] = malloc(50);
              lines[sizelines] = _strdup(s);
  
              sizelines++;
          }
      }
      else 
      {
          printf(&quot;Wrong file&quot;);
      }
  
      fclose(myFile);
  
      for (int i = 0; i &lt; strlen(lines); i++)
      {
          if (!strcmp(&quot;&lt;Name&gt;&quot;, lines[i]))
          {
              const char* s = lines[i];
  
              const char* PATTERN1 = &quot;&lt;Name&gt;&quot;;
              const char* PATTERN2 = &quot;&lt;/Name&gt;&quot;;
  
              char* target = NULL;
              char* start, * end;
  
              if (start = strstr(s, PATTERN1))
              {
                  start += strlen(PATTERN1);
                  if (end = strstr(start, PATTERN2))
                  {
                      target = (char*)malloc(end - start + 1);
                      memcpy(target, start, end - start);
                      target[end - start] = '\0';
                  }
              }
  
              if (target) printf(&quot;%s\n&quot;, target);
  
              free(target);
          }
      }
  </code></pre>