Mail Archives: djgpp/1997/08/14/04:22:16
On 13 Aug 97 at 20:08, Smith A. Cat wrote:
> when i run this:
>
> #include <stdio.h>
> 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.
- Raw text -