k+r book

Discussion in 'Mac Programming' started by jamesapp, Jun 11, 2008.

  1. macrumors 6502a

    Joined:
    Mar 7, 2008
    #1
    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:

    Code:
    #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?
     
  2. macrumors 68020

    brn2ski00

    Joined:
    Aug 16, 2007
    #2
    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.
     
  3. macrumors regular

    Joined:
    Mar 13, 2008
    #3
    try
    Code:
    #include "stdio.h"
    instead of syscalls.h. maybe the syscalls.h they have in the book already includes stdio.
     
  4. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #4
    It is possibly the most popular C programming book out. I wouldn't be surprised if the majority of C programmers owned it.
     
  5. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #5
    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.
     
  6. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    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.
     
  7. macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #7
    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>
     
  8. macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #8
    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.
     
  9. macrumors 65816

    Joined:
    Apr 19, 2004
    #9
    sounds like it is a file they created themselves like other say. might even be listed in the book.
     

Share This Page