NULL pointer problem on SUN

Thomas Heruska theruska at digi.lonestar.org
Sat Nov 10 10:03:32 AEST 1990


I am having trouble using the function strtok on a SUN.  The function
works perfectly on an HP and APOLLO system, so I am convinced that it is   
a specific SUN problem.  

I believe that the problem occurs due to the fact strtok returns a NULL 
pointer when it encounters the end of the string it is parsing.  I am trying
to copy this NULL pointer to another string and check that string for the NULL.
For some reason, it crashes at this point ONLY on the Sun.  Has anyone 
encountered this problem before?  It is obviously not a problem with strtok, but
rather with copying a NULL pointer to a string.  The man pages on strtok state
that a pointer to a null string must be used instead of a NULL pointer on the
Sun.  However, strtok only returns a NULL pointer.  I have tried casting
(char *) to the returned value from strtok, but it produces the same results.


   portion of code: 

   char token[50];
   char mesg[50];

   strcpy(mesg," \0");

   strcpy(token,strtok(mesg," \0"));    /* crashes here - should place
                                              a NULL pointer in token   */
   if (token[0] == NULL) 
       . 
       .
       .


Does anyone know how to get around this on a SUN?  

Please E-mail any suggestions.  Thanks in advance.



More information about the Comp.lang.c mailing list