Date: Thu, 14 Aug 1997 20:06:08 +1100 From: Bill Currie Subject: Re: why does this work like this (char allocation question)?? In-reply-to: <33EC75ED.2EA9@primenet.com> To: "Smith A. Cat" , djgpp AT delorie DOT com Message-id: <199708140810.UAA11528@teleng1.tait.co.nz gatekeeper.tait.co.nz> Organization: Tait Electronics Limited MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Comments: Authenticated sender is Precedence: bulk On 13 Aug 97 at 20:08, Smith A. Cat wrote: > when i run this: > > #include > char buffer[4]; > void main(void){ > printf("%s %d", gets(buffer), sizeof(buffer)); > } > [snip] > why doesn't it seg out as soon as the string exceeds four > characters?? there happened to be someting between buffer and a critical variable used by gets() (or one of the functions it calls) that weren't touched any other way. > > the same thing happens if you declare the string as a pointer > (*buffer). Ummm, pure luck? > > does a declared variable name automagically get 64 bytes of exercise > space?? Definitly not. For safer string input, use fgets; it takes the maximum buffer size as the second paramenter (ie fgets(buffer,maxlen,file)). Bill -- Leave others their otherness.