PDA

View Full Version : k+r book




jamesapp
Jun 11, 2008, 11:41 AM
reading from a book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. In the last chapter of the book, they discuss a file called syscalls.h,

from the book:

"We have collected function prototypes for the system calls into a file called syscalls.h so we can include it in the programs of this chapter. This name is not standard however."

I don't know where these functions are coming from.
the first program in the chapter is a program to copy input to output.
here is my source file which i called inputout.c:


#include "syscalls.h"

main() /* copy input to output */
{
char buf[BUFSIZ];
int n;

while ((n = read(0, buf, BUFSIZ)) > 0)
write(1, buf, n);
return 0;
}


when i went to compile it i got error messages saying that the file syscalls.h doesen't exist. does anyone know anything about syscalls.h?



brn2ski00
Jun 11, 2008, 11:42 AM
That was the same book that I used in college as well. Small world....

It sounds like syscalls.h is a KR specific header file. You may need to install or copy those files from (where ever) into your directory where the program is.

drivefast
Jun 11, 2008, 11:49 AM
try
#include "stdio.h"
instead of syscalls.h. maybe the syscalls.h they have in the book already includes stdio.

Cromulent
Jun 11, 2008, 12:02 PM
That was the same book that I used in college as well. Small world....

It is possibly the most popular C programming book out. I wouldn't be surprised if the majority of C programmers owned it.

ChrisA
Jun 11, 2008, 12:47 PM
reading from a book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. In the last chapter of the book, they discuss a file called syscalls.h,

K&R is a good book to have for historic reasons. It shows what programming C was like in the early days before ANSI C was the standard. I keep my copy of K&R right next to Griiswald's "SNOBOL" book, the MIT LISP 1.4 manual and Wirth's Pascal book. All of these are classics that are decades out of date. I got into programming back when Unix was the hot new thing in the early 70s

Today if you don't know what dot-H file to include just look up the man page for that funtion. I cut and paste the #include right out of the man page. After doing this a few times you learn the common ones.

Cromulent
Jun 11, 2008, 01:19 PM
K&R is a good book to have for historic reasons. It shows what programming C was like in the early days before ANSI C was the standard.

The 2nd Ed is ANSI C which is all you really need at the moment considering the failure of C99 to hit full mainstream adoption.

ScoobyMcDoo
Jun 11, 2008, 01:55 PM
Hmmm. I have the first edition still - it doesn't mention the syscalls.h file. Not sure why it would for that example. On my linux box, there is a syscalls.h file, but it would not be needed for this example.

As ChrisA said, use the man page - in your case type "man 2 read" and it will tell you what headers you need to include:

NAME
pread, read, readv -- read input

LIBRARY
Standard C Library (libc, -lc)

SYNOPSIS
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>

pilotError
Jun 11, 2008, 04:26 PM
In chapter 1 or 2 of the book, they created a header for all the future examples in the book. That's what the include file is.

I'm sure if you look in the TOC, you'll find the page number of the listing.

psingh01
Jun 12, 2008, 12:15 AM
sounds like it is a file they created themselves like other say. might even be listed in the book.