cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/14/03:22:53

From: "Smith A. Cat" <imbe AT primenet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: why does this work like this (char allocation question)??
Date: 13 Aug 1997 20:08:00 -0700
Organization: Blue Square Laboratories
Lines: 21
Message-ID: <33EC75ED.2EA9@primenet.com>
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

when i run this:

#include <stdio.h>
char buffer[4];
void main(void){
printf("%s  %d", gets(buffer), sizeof(buffer));
}

for an input string up to about 64 characters (i'm not sure how many due
to impatience...)  it echos the input string, and prints *4* for the
size.  when the string gets longer, it segs out.

why doesn't it seg out as soon as the string exceeds four characters??

the same thing happens if you declare the string as a pointer (*buffer).

does a declared variable name automagically get 64 bytes of exercise
space??

phil

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019