From owner-freebsd-questions Mon Apr 23 10:45:39 2001 Delivered-To: freebsd-questions@freebsd.org Received: from cactus.fi.uba.ar (cactus.fi.uba.ar [157.92.49.108]) by hub.freebsd.org (Postfix) with ESMTP id F2C6D37B422 for ; Mon, 23 Apr 2001 10:45:30 -0700 (PDT) (envelope-from fgleiser@cactus.fi.uba.ar) Received: from cactus.fi.uba.ar (cactus.fi.uba.ar [157.92.49.108]) by cactus.fi.uba.ar (8.9.3/8.9.3) with ESMTP id OAA66401; Mon, 23 Apr 2001 14:50:20 -0300 (ART) (envelope-from fgleiser@cactus.fi.uba.ar) Date: Mon, 23 Apr 2001 14:50:20 -0300 (ART) From: Fernando Gleiser To: david@angra.uac.pt Cc: questions@FreeBSD.ORG Subject: Re: fgets/fputs Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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