Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!olivea!samsung!usc!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: NULL pointer problem on SUN Message-ID: <14419@smoke.brl.mil> Date: 10 Nov 90 08:23:44 GMT References: <1255@digi.lonestar.org> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 20 In article <1255@digi.lonestar.org> theruska@digi.lonestar.org (Thomas Heruska) writes: >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. No, it's incorrect code on your part. > strcpy(token,strtok(mesg," \0")); /* crashes here - should place > a NULL pointer in token */ strcpy() requires valid source and destination pointer arguments. A null pointer doesn't point anywhere. Therefore it cannot be used to fetch a 0-char-terminated array of bytes from the source location. On systems where this APPEARS to work, it is only because on those systems there happens to be something innocuous (probably starting with a 0 byte value) at virtual address 0, and when strcpy() tries to use the pointer you supplied to it, it looks just like address 0. You should fix the code. Null pointers don't point anywhere.