----- Original Message ----- 
From: "John Matthews" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, June 08, 2008 9:28 AM
Subject: [c-prog] Re: verifiying input


--- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>
> On Sun, Jun 8, 2008 at 4:29 AM, John Matthews <[EMAIL PROTECTED]> wrote:
> > --- In [email protected], "Brett McCoy" <idragosani@> wrote:
> >>
> >> you need to allocate memory for char
> >> *input. And as I said before, buf[] is unnecessary. Create a #define
> >> like BUFSZ 10 and use that to allocate the memory using malloc, and
> >> remember your buffer needs to be BUFSZ + 1 to hold the terminating
> >> '\0'.
> >
> > Just wondering why you need to use malloc()? Eg.
>
> You don't need top use malloc() if you create an array, of course, but
> he was using a pointer and failed to allocate memory for it, so I was
> addressing that.

Right, understood.

I suspect that perhaps the OP just saw that the argument had to be a
pointer, and didn't realise that in this case at least an array would
be more appropriate?

   You have to watch for buffer overflow though. I wouldn't use gets() 
that's why I used fgets redirected to stdin.

Bill



Reply via email to