You may want to study the following link: strtok() and notice that you don't need to allocate memory for the pointer used in strtok(). Your present code has a memory leak because of this issue. Also...