title: A bug for char array in C
body: <p>I want to print the following html to the console in C.However, there is a bug in my code which made me really confused, and I have no clue how could that happen? The bug is it print the last char array again.</p>
  
  <p>Sample output:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;p&gt;Hey There!&lt;/p&gt;
          &lt;p&gt;You can search for things on the internet at:
              &lt;ul&gt;
              &lt;li&gt; &lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt; &lt;a href="http://www.bing.com"&gt;Bing&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/p&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  
  My output:
  &lt;html&gt;
      &lt;body&gt;
          &lt;p&gt;Hey There!&lt;/p&gt;
          &lt;p&gt;You can search for things on the internet at:
              &lt;ul&gt;
              &lt;li&gt; &lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;&lt;/li&gt;
              following line is incorrect. It prints the above line again.
              &lt;li&gt; &lt;a href="http://www.bing.com" href="http://www.google.com"&gt;Bing&lt;/a&gt;&lt;/li&gt; 
              &lt;/ul&gt;
          &lt;/p&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;string.h&gt;
  void open_tag(char tag[], char attribute[]){
  char str1[100];
  char str2[100];
  char str3[100];
  //The bug happens here.The attribute[] is incorrect.
  strcpy (str1,tag);
  strncat (str1, attribute, 100);
  strcpy (str2,"&lt;");
  strcpy (str3,"&gt;");
  strncat (str2, str1, 100);
  strncat (str2, str3, 50);
  printf ("%s",str2);
  }
  void close_tag(char tag[]){
  char str1[20];
  char str2[20];
  char str3[20];
  strcpy (str1,tag);
  strcpy (str2,"&lt;/");
  strcpy (str3,"&gt;");
  strncat (str2, str1, 6);
  strncat (str2, str3, 6);
  printf ("%s",str2);
  }
  
  int main(int argc, char *argv[])
  {
  open_tag("html", "");
  printf("\n");
  open_tag("body", "");
  printf("\n");
  open_tag("p", "");
  printf("Hey There!");
  close_tag("p");
  printf("\n");
  open_tag("p", "");
  printf("You can search for things on the internet at:");
  printf("\n");
  open_tag("ul", "");
  printf("\n");
  open_tag("li", "");
  char arr2[] = {' ','h','r','e','f','=','\"','h','t','t','p',':','/','/','w','w','w','.','g','o','o','g','l','e','.','c','o','m','\"'};
  open_tag("a", arr2);
  printf("Google");
  close_tag("a");
  close_tag("li");
  printf("\n");
  open_tag("li", "");
  char arr1[] = {' ','h','r','e','f','=','\"','h','t','t','p',':','/','/','w','w','w','.','b','i','n','g','.','c','o','m',' ','\"'};  
  open_tag("a", arr1);
  printf("Bing");
  close_tag("a");
  close_tag("li");
  printf("\n");
  close_tag("ul");
  printf("\n");
  close_tag("p");
  printf("\n");
  close_tag("body");
  printf("\n");
  close_tag("html");
  printf("\n");
  return 0;
  }
  </code></pre>