From owner-freebsd-questions Mon Apr 23 10:36:56 2001 Delivered-To: freebsd-questions@freebsd.org Received: from cgmd76206.chello.nl (d9168.upc-d.chello.nl [213.46.9.168]) by hub.freebsd.org (Postfix) with ESMTP id 8D45037B42C for ; Mon, 23 Apr 2001 10:36:54 -0700 (PDT) (envelope-from edwin@cgmd76206.chello.nl) Received: by cgmd76206.chello.nl (Postfix, from userid 1001) id 1412FF0; Mon, 23 Apr 2001 19:36:53 +0200 (CEST) Date: Mon, 23 Apr 2001 19:36:53 +0200 From: Edwin Groothuis To: David Cc: questions@freeBSD.org Subject: Re: fgets/fputs Message-ID: <20010423193652.A75199@cgmd76206.chello.nl> References: <0104231717100C.05409@david> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <0104231717100C.05409@david>; from david@angra.uac.pt on Mon, Apr 23, 2001 at 05:08:29PM +0000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, Apr 23, 2001 at 05:08:29PM +0000, David wrote: > 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) It says: s is a pointer to a character. > but the program only works when I define char[255] instead of > char* as I show in the source code below:...Why? In char str[255], str is a pointer to an allocated array of 255 characters. In char *str, str is a pointer to a char. If you use char str[255], fgets() has a place to put the data in (namely the 255 characters you allocated for it). If you use char *str, you have to allocate the memory first before you can let fgets() write into it. Edwin -- Edwin Groothuis | Personal website: http://www.MavEtJu.org edwin@mavetju.org | Interested in MUDs? Visit Fatal Dimensions: ------------------+ http://FatalDimensions.nl.eu.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message