title: char array split ip with strtok
body: <p>I'm trying to split a IP address like 127.0.0.1 from a file:</p>
  
  <p>using following C code:</p>
  
  <pre><code>pch2 = strtok (ip,".");
  printf("\npart 1 ip: %s",pch2);
  pch2 = strtok (NULL,".");
  printf("\npart 2 ip: %s",pch2);
  </code></pre>
  
  <p>And IP is a char ip[500], that containt an ip.</p>
  
  <p>When printing it prints 127 as part 1 but as part 2 it prints NULL?</p>
  
  <p>Can someone help me?</p>
  
  <p>EDIT:</p>
  
  <p>Whole function:</p>
  
  <pre><code>FILE *file = fopen ("host.txt", "r");
  char * pch;
  char * pch2;
  char ip[BUFFSIZE];
  IPPart result;
  
  if (file != NULL)
  {
      char line [BUFFSIZE]; 
      while(fgets(line,sizeof line,file) != NULL)
      {
          if(line[0] != '#')
          {
                              pch = strtok (line," ");
              printf ("%s\n",pch);
  
              strncpy(ip, pch, strlen(pch)-1);
              ip[sizeof(pch)-1] = '\0';
  
              //pch = strtok (line, " ");
              pch = strtok (NULL," ");
              printf("%s",pch);
  
  
              pch2 = strtok (ip,".");
              printf("\nDeel 1 ip: %s",pch2);
              pch2 = strtok (NULL,".");
              printf("\nDeel 2 ip: %s",pch2);
              pch2 = strtok(NULL,".");
              printf("\nDeel 3 ip: %s",pch2);
              pch2 = strtok(NULL,".");
              printf("\nDeel 4 ip: %s",pch2);
  
          }
      }
      fclose(file);
  }
  </code></pre>