From owner-freebsd-questions Mon Oct 2 11:47:18 1995 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id LAA14627 for questions-outgoing; Mon, 2 Oct 1995 11:47:18 -0700 Received: from rocky.sri.MT.net (sri.MT.net [204.94.231.129]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id LAA14622 for ; Mon, 2 Oct 1995 11:47:14 -0700 Received: (from nate@localhost) by rocky.sri.MT.net (8.6.12/8.6.12) id MAA29706; Mon, 2 Oct 1995 12:48:05 -0600 Date: Mon, 2 Oct 1995 12:48:05 -0600 From: Nate Williams Message-Id: <199510021848.MAA29706@rocky.sri.MT.net> To: olsenc@ichips.intel.com Cc: questions@freebsd.org Subject: Re: If not gets(), then what? In-Reply-To: <9510021814.AA35311@dtt034.intel.com> References: <9510021814.AA35311@dtt034.intel.com> Sender: owner-questions@freebsd.org Precedence: bulk > I have a program that uses gets(), and FreeBSD complains about it. > I read the manpage on gets(), and it says it's dangerous, but yet > it doesn't mention any alternatives! Well, it's not conmpletely obvious, but the other routine mentioned in the same man-page is the better solution. Instead of: { char foo[255]; char *ptr; #if defined(BAD_CODE) gets(foo); #else fgets(foo, 255, stdin); c = index(foo, '\n'); if ( c != NULL ) *c = '\0'; #endif } The use of the index call is necessary to strip off the trailing '\n'. Nate