OT: Trying to learn C -- some questions

Adam Fabian afabian at austin.rr.com
Thu Nov 25 17:40:49 PST 2004


On Thu, Nov 25, 2004 at 07:38:10PM -0500, Tom Parquette wrote:

> 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?

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 <curses.h>" 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 at austin.rr.com)


More information about the freebsd-questions mailing list