🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #53645

Re: Is this sscanf a valid construct?

#53645
From: Richard Tobin
Date: Fri, 20 Sep 1991 13:38
15 lines
950 bytes
> Is the following code valid C:

>   char *s = "abcd";

>   sscanf( string, " %c %c", &s[0], &s[1] );

> But with GNU gcc, I get
>  abcd
> Segmentation fault (core dumped)

You're trying to modify a literal string.  By default, gcc stores these
in a read-only area, so you can't modify them.  If you compile with the
flag -fwritable-strings it will work as expected.

-- Richard
Technical Details
Message-ID: <16629.9109201338@subnode.aiai.ed.ac.uk>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!aiai.edinburgh.ac.UK!richard

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,ed55ad3eb93288ba
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1991-09-21 08:53:14 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!aiai.edinburgh.ac.UK!richard
From: richard@aiai.edinburgh.ac.UK (Richard Tobin)
Newsgroups: gnu.gcc.help
Subject: Re: Is this sscanf a valid construct?
Message-ID: <16629.9109201338@subnode.aiai.ed.ac.uk>
Date: 20 Sep 91 13:38:55 GMT
Sender: daemon@cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 15