title: C strip html between <...>
body: <p>How can i strip the HTML from  document between and including the &lt;...> tags in a HTML document using C? My current program uses curl to get the contents of the webpage and puts it into a text file, it then reads from the text file and removes the &lt;>, but i am unsure of how to remove everything between those tags.</p>
  
  <pre><code>#include &lt;curl/curl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;unistd.h&gt;
  
  #define WEBPAGE_URL "http://homepages.paradise.net.nz/adrianfu/index.html"
  #define DESTINATION_FILE "/home/user/data.txt"
  
  size_t write_data( void *ptr, size_t size, size_t nmeb, void *stream)
  {
   return fwrite(ptr,size,nmeb,stream);
  }
  
  int main()
  {
   int in_tag = 0;
   char * buffer;
   char c;
   long lSize;
   size_t result;
  
   FILE * file = fopen(DESTINATION_FILE,"w+");
   if (file==NULL) {
      fputs ("File error",stderr); 
      exit (1);
      }
  
   CURL *handle = curl_easy_init();
   curl_easy_setopt(handle,CURLOPT_URL,WEBPAGE_URL); /*Using the http protocol*/
   curl_easy_setopt(handle,CURLOPT_WRITEFUNCTION, write_data);
   curl_easy_setopt(handle,CURLOPT_WRITEDATA, file);
   curl_easy_perform(handle);
   curl_easy_cleanup(handle);
  
    int i, nRead, fd;
      int source;
      char buf[1024];
  
  
      if((fd = open("data.txt", O_RDONLY)) == -1)
      {
          printf("Cannot open the file");
      }
      else
      {
          nRead = read(fd, buf, 1024);
          printf("Original String ");
          for(i=0; i&lt;nRead; i++)
          {
                  printf("%c", buf[i]);
          }
  
          printf("\nReplaced String ");
  
          for(i=0; i&lt;nRead; i++)
          {
              if(buf[i]=='&lt;' || buf[i]=='&gt;'){
              buf[i]=' ';
  
              }
              printf("%c", buf[i]);
          }
      }
      close(source);
  
   return 0;
   }
  </code></pre>