Help...

Austin Ziegler austin at bucsf.bu.edu
Tue Oct 10 12:07:14 AEST 1989


On 9 Oct 89 23:26:06 GMT,
dnewton at carroll1.UUCP (Dave 'Yes, I'm weird' Newton) said:
Dave> Relay-Version: version B 2.10.3 4.3bds beta 6/6/85; site bu-cs.BU.EDU
Dave> Date-Received: 10 Oct 89 01:39:31 GMT

Dave> Why doesn't this work?

Dave> ==========================
Dave> #include <stdio.h>
Dave> main ()
Dave> {
Dave>    char      h[];
Dave>    scanf ("%s", h);
Dave>    printf ("%s\n", h);
Dave> }
Dave> ==========================

Dave>   It seems innocent enuf, but just prints garbage.  I'm missing something
Dave> obvious, but I'll be darned if I know what it is.

    I don't know, but I just tried it.  One possibility is to strcat a \0
to the end of h before printf'ing h.  Otherwise, you can get the same
result from char *h, and not get too many problems.

\|/ Elminster, Sage of Shadowdale 
-*- 
/|\ austin at bucsf.bu.edu



More information about the Comp.lang.c mailing list