Help...

Orn E. Hansen orn at rsp.is
Fri Oct 13 23:01:23 AEST 1989


In article <39902 at bu-cs.BU.EDU>, austin at bucsf.bu.edu (Austin Ziegler) writes:
> On 9 Oct 89 23:26:06 GMT,
> dnewton at carroll1.UUCP (Dave 'Yes, I'm weird' Newton) said:
> 
> Dave> ==========================
> Dave> #include <stdio.h>
> 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 at rsp.is
Computer Department.



More information about the Comp.lang.c mailing list