Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Apr 2001 14:50:20 -0300 (ART)
From:      Fernando Gleiser <fgleiser@cactus.fi.uba.ar>
To:        david@angra.uac.pt
Cc:        questions@FreeBSD.ORG
Subject:   Re: fgets/fputs
Message-ID:  <Pine.BSF.4.21.0104231437160.61971-100000@cactus.fi.uba.ar>

next in thread | raw e-mail | index | archive | help
> I have a doubt on libc:
> 
> Both fputs and fgets functions use a char* instead of char[255]
> fgets (char *s, int count, FILE *stream)
> fputs (const char *s, FILE *stream)
> 
> but the program only works when I define char[255] instead of char* as I show
> in the source code below:...Why?

If you declare str to be a char *, you need to initialize it calling 
malloc(3) to allocate memory. If you don't do it, when you try to copy
data to the buffer pointed to by str, you get a segfault and the 
program dies 



				Fer


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0104231437160.61971-100000>