From owner-freebsd-questions@FreeBSD.ORG  Fri Nov 26 03:03:21 2004
Return-Path: <owner-freebsd-questions@FreeBSD.ORG>
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 1B7E616A4CE
	for <freebsd-questions@freebsd.org>;
	Fri, 26 Nov 2004 03:03:21 +0000 (GMT)
Received: from out002.verizon.net (out002pub.verizon.net [206.46.170.141])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3566543D58
	for <freebsd-questions@freebsd.org>;
	Fri, 26 Nov 2004 03:03:20 +0000 (GMT)
	(envelope-from ringworm@inbox.lv)
Received: from ringworm.mechee.com ([4.26.226.89]) by out002.verizon.net
          (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP
          id <20041126030319.OWMP3388.out002.verizon.net@ringworm.mechee.com>;
          Thu, 25 Nov 2004 21:03:19 -0600
Received: by ringworm.mechee.com (Postfix, from userid 1001)
	id A22662CE78F; Thu, 25 Nov 2004 19:01:15 -0800 (PST)
From: "Michael C. Shultz" <ringworm@inbox.lv>
To: freebsd-questions@freebsd.org
Date: Thu, 25 Nov 2004 19:01:13 -0800
User-Agent: KMail/1.7.1
References: <41A67AF2.1060803@twcny.rr.com>
In-Reply-To: <41A67AF2.1060803@twcny.rr.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200411251901.14249.ringworm@inbox.lv>
X-Authentication-Info: Submitted using SMTP AUTH at out002.verizon.net from
	[4.26.226.89] at Thu, 25 Nov 2004 21:03:18 -0600
cc: Tom Parquette <BCSFD204@twcny.rr.com>
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 <freebsd-questions.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>,
	<mailto:freebsd-questions-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-questions>
List-Post: <mailto:freebsd-questions@freebsd.org>
List-Help: <mailto:freebsd-questions-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>,
	<mailto:freebsd-questions-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Nov 2004 03:03:21 -0000

On Thursday 25 November 2004 04:38 pm, Tom Parquette wrote:
> Hi.  This is a little off topic but I'm hoping someone can provide
> some guidance and answer a few questions.  TIA.
>
> 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'm having some trouble with some of the "homework" in the book.
> I think I know some of the answers but I would like to confirm my
> understanding.
> Some of the following I have no clue about.
>
> 1) gcc complains that <conio.h> was not found.  If I comment out the
> #include, the program compiles.  Is this a DOSism or something else?
>
> 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 suggest you learn one function well, then expand from there. fprintf 
is a good place to start. 

man 3 fprintf has the following:

LIBRARY
     Standard C Library (libc, -lc)

means this command is in libc, 

lib is always stripped when you use -l to include a library
when you compile so -lc means include libc.
-lc is automatically included when you compile with gcc
so you usually don't need it.

SYNOPSIS
     #include <stdio.h>

that means include stdio.h when you use fprintf

fprintf(stdout, "hello\n") will print to the screen
and so will fprintf(stderr, "hello\n").  You can replace
stdout/stderr with a filestream for example:

sample code:

#include	<stdio.h>

FILE*	fileStream;
fileStream	= fopen( "hello.txt", "w");
fprintf( stdout,"hello\n");
fprintf( fileStream,"hello\n");
fclose(fileStream);

save as hello.c
compile with
gcc hellow.c -o hello
run and it will print "hello" to the screen and create a file
"hello.txt" with hello printed in the file.

Once your really comfortable with fprintf then look up the man
page and google the next command you want to learn.  Google
beats any programming books in my opinion once you learn to use it.

If you get stuck on one specific command, feel free to email me directly
and I'll give you a pointer if I know it.

-Mike