Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Apr 2001 19:36:53 +0200
From:      Edwin Groothuis <edwin@mavetju.org>
To:        David <david@angra.uac.pt>
Cc:        questions@freeBSD.org
Subject:   Re: fgets/fputs
Message-ID:  <20010423193652.A75199@cgmd76206.chello.nl>
In-Reply-To: <0104231717100C.05409@david>; from david@angra.uac.pt on Mon, Apr 23, 2001 at 05:08:29PM %2B0000
References:  <0104231717100C.05409@david>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010423193652.A75199>