From owner-freebsd-questions@FreeBSD.ORG Fri Nov 26 01:40: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 1A10A16A4CE for ; Fri, 26 Nov 2004 01:40:49 +0000 (GMT) Received: from ms-smtp-01-eri0.texas.rr.com (ms-smtp-01.texas.rr.com [24.93.47.40]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5C4DC43D4C for ; Fri, 26 Nov 2004 01:40:48 +0000 (GMT) (envelope-from afabian@austin.rr.com) Received: from turingmachine.mentalsiege.net (cs70112247-52.austin.rr.com [70.112.247.52])iAQ1eaYm006121 for ; Thu, 25 Nov 2004 19:40:40 -0600 (CST) Received: from turingmachine.mentalsiege.net (turingmachine.mentalsiege.net [127.0.0.1])iAQ1dfXN064324 for ; Thu, 25 Nov 2004 19:39:46 -0600 (CST) (envelope-from afabian@turingmachine.mentalsiege.net) Received: (from afabian@localhost)iAQ1ddc7063291 for freebsd-questions@freebsd.org; Thu, 25 Nov 2004 19:39:39 -0600 (CST) (envelope-from afabian) Date: Thu, 25 Nov 2004 19:39:32 -0600 From: Adam Fabian To: "freebsd-questions@freebsd.org" Message-ID: <20041126013932.GA96301@turingmachine.mentalsiege.net> Mail-Followup-To: "freebsd-questions@freebsd.org" References: <41A67AF2.1060803@twcny.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41A67AF2.1060803@twcny.rr.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: Symantec AntiVirus Scan Engine 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 01:40:49 -0000 On Thu, Nov 25, 2004 at 07:38:10PM -0500, Tom Parquette wrote: > 1) gcc complains that was not found. If I comment out the > #include, the program compiles. Is this a DOSism or something else? Yes, it is. > 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. I don't remember DOS having any concept of a default printer, and a vague recollection of stdprn actually being something more like UNIX's stdout. But I could be misremembering. > 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. > I looked at the man page and found fgets. I do not understand from the > fgets man page how I'm supposed to code this. I've tried a number of > things along the lines of > fgets(rec.fname,sizeof(rec.fname)); > but gcc does not like anything I've tried. It keeps telling me I have > "too few arguments fo function `fgets'" Help! fgets take three parameters, and I only see two there. It looks like you need fgets(rec.fname,sizeof(rec.fname),stdin) or something of the like. gets() is vulnerable to buffer-overflows, but if you're just writing some quick, throw-away programs, it doesn't really matter. On the other hand, no reason not to get used to doing something more correct. > 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 believe you will need -lcurses in your gcc command to link against the curses library. The headers declare the functions, but the actual machine code has to come from the library. -- Adam Fabian (afabian@austin.rr.com)