Re: OT: Trying to learn C -- some questions
> 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 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: OT: Trying to learn C -- some questions
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 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 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 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 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: OT: Trying to learn C -- some questions
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. 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. 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. 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) -- David Fleck [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: OT: Trying to learn C -- some questions
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 ([EMAIL PROTECTED]) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
OT: Trying to learn C -- some questions
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 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. 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! 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? Thanks... ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"