From owner-freebsd-questions Mon Apr 23 10:34:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from dualcpus.com (dualcpus.com [65.160.20.195]) by hub.freebsd.org (Postfix) with SMTP id 7ADF337B424 for ; Mon, 23 Apr 2001 10:34:38 -0700 (PDT) (envelope-from jgowdy@home.com) Received: (qmail 9593 invoked from network); 23 Apr 2001 17:34:37 -0000 Received: from sherline.cts.com (HELO server2) (204.216.163.132) by dualcpus.com with SMTP; 23 Apr 2001 17:34:37 -0000 Message-ID: <000701c0cc1b$a7c458a0$015778d8@sherline.net> From: "Jeremiah Gowdy" To: , References: <0104231717100C.05409@david> Subject: Re: fgets/fputs Date: Mon, 23 Apr 2001 10:34:27 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG ----- Original Message ----- From: "David" To: Sent: Monday, April 23, 2001 10:08 AM Subject: fgets/fputs > 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) Dude, why would they use char[255] ? They're any size you allocate. void main(void) { char str[255]; fgets(str,255,stdin); fputs(str,stdout); } or void main(void) { char *str; str=malloc(255); fgets(str,255,stdin); fputs(str,stdout); } > but the program only works when I define char[255] instead of char* as I show in > the source code below:...Why? char[255] allocates 255 bytes of data. char* is only a pointer, which points to nothing until you allocate some memory for it to point to. Your question is not really about libc. It's about a lack of basic understanding of "strings" (or lack therof) and pointers in C. You need a C programming book. The questions you're asking would be the first 3 chapters of any good C book. Good luck :) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message