🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6003

Re: gcc 2.7.2 problem with strtok()

#6003
From: Alain Magloire
Date: Fri, 27 Dec 1996 00:00
44 lines
1350 bytes
M.Wang (xiaofei@lucent.com) wrote:
: what is wrong with the following program?

: #include <stdio.h>
: #include <string.h>

: int
: main()
: {
: strtok("a b c", " ");
: return 0;
: }

: It generate the following error message: 

: (15:48)(/home/mwang/c)gcc 1.c
: (15:48)(/home/mwang/c)./a.out
: Memory fault(coredump)

: Thanks

well "a b c" is a __string constant__ i.e non-writable
strtok() will try to shove a null('\0') after the 'a'
hence the coredump

try this instead
.
main()
{
  char string[10] = "a b c";

  strtok(string, " ");
  return 0;
}

string is not a __string constant__ but an array of
10 chars.
If you have difficulties with string in C. The
C FAQ is ...priceless even for old timer who
sometimes get burn ;-)

--
bonne anne'e, alain
Technical Details
Message-ID: <59vs48$s6q@sifon.cc.mcgill.ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <59vbmi$9i0@nntpb.cb.lucent.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,18b9f2c0ce00f3
X-Google-Attributes: gid113d02,public
From: alainm@macs.ee.mcgill.ca (Alain Magloire)
Subject: Re: gcc 2.7.2 problem with strtok()
Date: 1996/12/27
Message-ID: <59vs48$s6q@sifon.cc.mcgill.ca>
X-Deja-AN: 206163052
sender: bug-gcc-request@prep.ai.mit.edu
references: <59vbmi$9i0@nntpb.cb.lucent.com>
organization: McGill University, Montreal, Canada.
x-gateway: relay7.UU.NET from bug-gcc to gnu.gcc.bug; Fri, 27 Dec 1996 02:01:13 EST
newsgroups: gnu.gcc.bug