Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!hafro!isgate!krafla!rispa2!orn From: orn@rsp.is (Orn E. Hansen) Newsgroups: comp.lang.c Subject: Re: Help... Message-ID: <142@.rsp.is> Date: 13 Oct 89 13:01:23 GMT References: <731@carroll1.UUCP> <39902@bu-cs.BU.EDU> Organization: National Hospital of Iceland Lines: 28 In article <39902@bu-cs.BU.EDU>, austin@bucsf.bu.edu (Austin Ziegler) writes: > On 9 Oct 89 23:26:06 GMT, > dnewton@carroll1.UUCP (Dave 'Yes, I'm weird' Newton) said: > > Dave> ========================== > Dave> #include > Dave> main () > Dave> { > Dave> char h[]; > Dave> scanf ("%s", h); > Dave> printf ("%s\n", h); > Dave> } > Dave> ========================== > The code 'char h[]' equals 'char *h'. This pointer doesn't point to any space that can hold any value's, it points to a random point naturally giving random results. The pointer probably points to your stack (the unused portion), so when calling 'printf' it alters the space scanned by 'scanf' thus printing garbage (I guess ...). ------------------------------------------------------------------------ Orn Hansen National Hospital of Iceland, Internet: orn@rsp.is Computer Department.