title: Copying a strstr search in a string to the string itself
body: <p>I'm trying to parse a web page and extract weather info from it with C (masochist, I know).</p>
  
  <p>Among other things in that page, there are these lines:</p>
  
  <pre><code>           &lt;dt&gt;Chance of &lt;span class='wx-firstletter'&gt;rain&lt;/span&gt;:&lt;/dt&gt;
  
                      &lt;dt&gt;Wind:&lt;/dt&gt;
  
          &lt;dt&gt;Humidity:&lt;/dt&gt;
  
          &lt;dt&gt;UV Index:&lt;/dt&gt;
  
  &lt;dt&gt;Snowfall:&lt;/dt&gt;
  
          &lt;dt&gt;Sunrise:&lt;/dt&gt;
  
          &lt;dt&gt;Moonrise:&lt;/dt&gt;
  
          &lt;dt&gt;Moonphase:&lt;/dt&gt;
  
                      &lt;dt&gt;Past 24-hr Precip:&lt;/dt&gt;
  
          &lt;dt&gt;Past 24-hr Snow:&lt;/dt&gt;
  
             &lt;dt&gt;Chance of &lt;span class='wx-firstletter'&gt;rain&lt;/span&gt;:&lt;/dt&gt;
  
                      &lt;dt&gt;Wind:&lt;/dt&gt;
  
          &lt;dt&gt;Humidity:&lt;/dt&gt;
  
          &lt;dt&gt;UV Index:&lt;/dt&gt;
  
  &lt;dt&gt;Snowfall:&lt;/dt&gt;
  
          &lt;dt&gt;Sunset:&lt;/dt&gt;
  
          &lt;dt&gt;Moonset:&lt;/dt&gt;
  
          &lt;dt&gt;Moonphase:&lt;/dt&gt;
  
                      &lt;dt&gt;Past 24-hr Precip:&lt;/dt&gt;
  
          &lt;dt&gt;Past 24-hr Snow:&lt;/dt&gt;
  </code></pre>
  
  <p>After I've downloaded the page, saved it in a file and read it with in an array with fread, I use a loop to read the array line by line, saving it to a temporary array (tmp).
  The part that handles the lines containing the string &lt; dt > is the following.</p>
  
  <pre><code>   } else if (strstr(tmp,"&lt;dt&gt;")) {
         strcpy(tmp,strstr(tmp,"&lt;dt&gt;")+4);
         strcpy(strstr(tmp,"&lt;/dt&gt;")," \0");
         if (strstr(tmp,"Chance of"))
                 strcpy(tmp,"Chance of precipitation: ");
         fwrite(tmp,1,strlen(tmp),file_tod);
     } else if ....
  </code></pre>
  
  <p>Everything goes well, apart from the Moonphase and Past 24h snow lines.</p>
  
  <pre><code>Chance of precipitation: 
  Wind: 
  Humidity: 
  UV Index: 
  Snowfall: 
  Sunrise: 
  Moonrise: 
  Mo&gt;
  phase: 
  Past 24-hr Precip: 
  Paw: 24-hr Snow: 
  Chance of precipitation: 
  Wind: 
  Humidity: 
  UV Index: 
  Snowfall: 
  Sunset: 
  Moonset: 
  Mo&gt;
  phase: 
  Past 24-hr Precip: 
  Paw: 24-hr Snow: 
  </code></pre>
  
  <p>Instead of getting Moonphase:, I get Mo>\nphase: and instead of getting Past 24h-Snow:, I get Paw: 24-hr Snow:.
  The strange thing is that is happening with only these particular strings.
  Can't I copy the result of strstr on a string to the string itself?</p>
  
  <p>strcpy(tmp,strstr(tmp,"")+4);</p>
  
  <p>Is this the offending line? I use the same method all over the rest of the code without problems.
  If I use an intermediate variable (buff) to store the result of the strstr search</p>
  
  <pre><code>} else if (strstr(tmp,"&lt;dt&gt;")) {
      strcpy(buff,strstr(tmp,"&lt;dt&gt;")+4);
      strcpy(strstr(buff,"&lt;/dt&gt;")," \0");
      if (strstr(buff,"Chance of"))
              strcpy(buff,"Chance of precipitation: ");
      fwrite(tmp,1,strlen(buff),file_tod);
  } else if .... 
  </code></pre>
  
  <p>everything's ok.</p>
  
  <p>Thanks for any answer and sorry if it is very obvious.</p>
  
  <p>EDIT: Came up with this</p>
  
  <pre><code>   } else if (strstr(tmp,"&lt;dt&gt;")) {
         memmove(tmp,strstr(tmp,"&lt;dt&gt;")+4,strlen(tmp)-(strlen(strstr(tmp,"&lt;dt&gt;")+4)));
         *(strstr(tmp,":")+1)=' ';
         *(strstr(tmp,":")+2)='\0';
         if (strstr(tmp,"Chance of"))
                 strcpy(tmp,"Chance of precipitation: ");
         fwrite(tmp,1,strlen(tmp),file_tod);
  </code></pre>
  
  <p>Is it legit?</p>