home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.os2.programmer
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!pacbell.com!decwrl!ampex!cjensen
- From: cjensen@ampex.com (Colin Jensen)
- Subject: Re: EMX library bug.
- Message-ID: <1992Jul22.185306.10692@ampex.com>
- Sender: usenet@ampex.com (News Poster)
- Nntp-Posting-Host: mer-s4-14
- Organization: Ampex Corporation, Redwood City CA
- References: <ReiBoB5w164w@dvss.UUCP>
- Date: Wed, 22 Jul 1992 18:53:06 GMT
- Lines: 21
-
- In article <ReiBoB5w164w@dvss.UUCP> dvss!jtroy@udel.edu (Jay Troy) writes:
- >I think I've discovered an EMX library bug. The standard library function
- >strtok causes an access violation in every combination that I've tried. The
- >following simple C program illustrates this problem:
-
- > char *ch = "3.4 4.1";
- > strcpy(temp, strtok(ch," "));
-
- I don't know anything about EMX, but your code is certainly problematic.
- A C compiler is free to store strings constants like "3.4 4.1" in
- read-only memory [hence their name]. Since strtok will try to write
- into that memory, an access violation should be expected.
-
- To be portable, you need to copy that string either into an automatic variable
- or copy it into some malloc'ed memory.
-
- Under UNIX, you can pass gcc the option -fwritable-strings to tell gcc you
- really want to be able to write into string constants. Perhaps this would
- solve your problem with EMX.
- --
- Colin Jensen (cjensen@ampex.com)
-