title: domain name parsing
body: <p>I have this code:</p>
  
  <pre><code>        #include &lt;stdio.h&gt;
          #include &lt;string.h&gt;
  
          int main()
          {
           char buf[255];
           char buf2[255];
           char myhost[255] = "subdomain.domain.com";
  
           char *pch;
           int token_counter = 0;
  
           memset(buf, 0, 255);
           memset(buf2, 0, 255);
           pch = strtok(myhost, ".");
           while (pch != NULL)
             {
                  pch = strtok(NULL, ".");
                  if (pch == NULL)
                     {
                          memset(buf, 0, 255);
                          strncpy(buf, buf2, strlen(buf2) - 1);
                          break;
                     }
                  token_counter++;
                  strcat(buf2, pch);
                  strcat(buf2, ".");
             }
           printf("Domain: %s\n", buf);
           return 0;
          }
  </code></pre>
  
  <p>this is working fine if myhost is defined as subdomain.domain.com but if it's domain.com it shows "com" as final result.</p>
  
  <p><em><strong>How can I make it detect correctly if it's a subdomain or a domain? Maybe if I include a list of known tlds?</em></strong></p>