From owner-freebsd-questions@FreeBSD.ORG Fri Nov 26 03:03:49 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A4FE516A4CE for ; Fri, 26 Nov 2004 03:03:49 +0000 (GMT) Received: from skippyii.compar.com (mail.compar.com [216.208.38.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id D82BA43D39 for ; Fri, 26 Nov 2004 03:03:47 +0000 (GMT) (envelope-from matt@gsicomp.on.ca) Received: from hermes (CPE00062566c7bb-CM000039c69a66.cpe.net.cable.rogers.com [69.193.82.185])iAQ3AoU2053417; Thu, 25 Nov 2004 22:10:52 -0500 (EST) (envelope-from matt@gsicomp.on.ca) Message-ID: <001c01c4d364$2f337bb0$1200a8c0@gsicomp.on.ca> From: "Matt Emmerton" To: "David Fleck" , "Tom Parquette" References: <41A67AF2.1060803@twcny.rr.com> <20041125202210.O48346@grond.sourballs.org> Date: Thu, 25 Nov 2004 22:01:06 -0500 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 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 cc: freebsd-questions@freebsd.org Subject: Re: OT: Trying to learn C -- some questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2004 03:03:49 -0000 > On Thu, 25 Nov 2004, Tom Parquette wrote: > > I'm trying to learn ANSI C using a book circa 1994. It is written from > > a DOS perspective. Someone at work, who knows a little C, told me that > > the book was "close enough". > > I think they are probably wrong. > > > 1) gcc complains that was not found. If I comment out the > > #include, the program compiles. Is this a DOSism or something else? > > I don't know if it's a DOSism, but it's definitely not a standard header > file in the UNIX world. I've never encountered it outside of Microsoft > systems. This is definitely a DOSism. On UNIX, most of the functionality in conio.h can be found in stdio.h or curses.h. > > 2) fprintf is described with stdprn being valid for a default printer. This > > does not seem to be valid in, at least, the FreeBSD world. man fprintf did > > not really help. I believe I have to create a stream for the print but I'm > > not clear on how to do it. > > Sorry, not sure about this, but again, it sounds like a DOS (or MS) > specific implementation. stdprn is definitely another DOSism. If you want to print directly to a printer, you have a bunch of choices: 1) write the output to a temporary file, and then use lpr to print the file to a printer (defined in /etc/printcap) 2) open a stream to /dev/lpt0 and fprintf directly to it -- this assumes that your printer is attached to parallel port 1. > > 3) gets() is used in a number of places. Using this gets me: > > /var/tmp//cciWrf9n.o(.text+0x20d): In function `get_data': > > : warning: warning: this program uses gets(), which is unsafe. > > 'gets()' will still work, but its use isn't advised. If you're just using > it in test programs, though, it's not a big deal. Regardless, you should convert your code to use fgets(), as it prevents against buffer overflow problems. > > 4) A couple of the home work assignments use getch(). I figured out from the > > getch man page that I needed "#include " but that changes the > > errors to: > > /var/tmp//cc1GEzyG.o(.text+0x6a): In function `main': > > : undefined reference to `stdscr' > > /var/tmp//cc1GEzyG.o(.text+0x6f): In function `main': > > : undefined reference to `wgetch' > > I do not know what header file I should be including. > > Or is there something else I'm not understanding? > > I think the real problem hear is that the getch() the example is > referencing is actually a function found in conio.h. The getch() in > curses probably isn't the one you want anyway. > (Ref.: http://lists.apple.com/archives/mpw-dev/2001/Aug/msg00182.html) The version of getch() should work fine, although you could use fgets() from stdin instead. -- Matt Emmerton