NULL pointer problem on SUN
Gary Mills
mills at ccu.umanitoba.ca
Sun Nov 11 10:00:33 AEST 1990
In <1255 at digi.lonestar.org> theruska at digi.lonestar.org (Thomas Heruska) writes:
>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.
You have a serious misconception about NULL. A NULL pointer does not point to
a null character. In fact, a NULL pointer does not point at all. Neither is
a NULL pointer the same as a null string. When you have a pointer that you
suspect may be NULL, you must test the pointer before referring to the object
at which the pointer points. This way should work on all the machines:
char token[50];
char mesg[50];
char *ptr;
strcpy(mesg," \0");
ptr = strtok(mesg," \0");
if ( ptr != NULL ) {
strcpy(token, ptr);
.
.
.
--
-Gary Mills- -Networking Group- -U of M Computer Services-
More information about the Comp.lang.c
mailing list