Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!fernwood!vixie!avsd!childers From: childers@avsd.UUCP (Richard Childers) Newsgroups: comp.lang.c Subject: Re: Help... Message-ID: <2142@avsd.UUCP> Date: 11 Oct 89 17:28:06 GMT References: <731@carroll1.UUCP> Reply-To: childers@avsd.UUCP (Richard Childers) Organization: Metaprogrammers International Lines: 40 dnewton@carroll1.cc.edu (Dave 'Yes, I'm weird' Newton) writes: >Why doesn't this work? > >#include >main () >{ > char h[]; > scanf ("%s", h); > printf ("%s\n", h); >} I compiled it and ran it without problems, on a Sun 3/50 running SunOS 3.5. It did complain about a segmenttation fault and dump core, though. Probably related to the fact that nowhere is the size of h[] defined. I defined it and the problem went away. If you think about it from the compiler's point of view, it makes sense. It allocates space as it is told to. If you don't allocate space, it might or might not make an educated guess, hand you a predetermined buffer of a fixed size, or hand you nothing but a pointer to a single byte, assuming you mean to define h[] as h[1]. > It seems innocent enuf, but just prints garbage. I'm missing something >obvious, but I'll be darned if I know what it is. Hope this is of assistance ... >David L. Newton | dnewton@carroll1.UUCP | Quote courtesy of >(414) 524-7343 (work) | dnewton@carroll1.cc.edu | Marie Niechwiadowicz, >(414) 524-6809 (home) | 100 NE Ave, Waukesha, WI 53186 | Boston College. -- richard -- * A CITIZEN: "Who might you be ? Samson ? --" * * CYRANO: "Precisely. Would you kindly lend me your jawbone ?" * * from _Cyrano de Bergerac_, by Edmond Rostand * * ..{amdahl|decwrl|octopus|pyramid|ucbvax}!avsd.UUCP!childers *