K & R 2 program about low level file input/ouptut not running - Unix

This is a discussion on K & R 2 program about low level file input/ouptut not running - Unix ; This program appears on page 171 the first paragraph and it is supposed to copy input to output but it is giving me errors - #include "syscalls.h" main() { char buf[BUFSIZE]; int n; while((n = read(0,buf, BUFSIZ))> 0) write(1, buf, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: K & R 2 program about low level file input/ouptut not running

  1. K & R 2 program about low level file input/ouptut not running

    This program appears on page 171 the first paragraph and it is
    supposed to copy input to output but it is giving me errors -

    #include "syscalls.h"

    main()
    {

    char buf[BUFSIZE];
    int n;
    while((n = read(0,buf, BUFSIZ))> 0)
    write(1, buf, n);

    return 0;

    }

    It is sayin BUFSIZ not declared but according to K & R 2 it is defined
    in syscalls.h



  2. Re: K & R 2 program about low level file input/ouptut not running

    WANG Cong wrote:
    > On Thu, 13 Mar 2008 02:43:29 -0700,broli wrote:
    >
    >> This program appears on page 171 the first paragraph and it is supposed
    >> to copy input to output but it is giving me errors -
    >>
    >> #include "syscalls.h"
    >>
    >> main()
    >> {
    >>
    >> char buf[BUFSIZE];
    >> int n;
    >> while((n = read(0,buf, BUFSIZ))> 0)
    >> write(1, buf, n);
    >>
    >> return 0;
    >>
    >> }
    >>
    >> It is sayin BUFSIZ not declared but according to K & R 2 it is defined
    >> in syscalls.h

    >
    >
    > syscalls.h is not a standard header. And 'read' and 'write' are
    > not standard library functions, neither. In fact, they're POSIX
    > functions.
    >

    Come on - this is a Unix newsgroup!

    Try including instead.

    Robert

  3. Re: K & R 2 program about low level file input/ouptut not running

    On Thu, 13 Mar 2008 02:43:29 -0700,broli wrote:

    > This program appears on page 171 the first paragraph and it is supposed
    > to copy input to output but it is giving me errors -
    >
    > #include "syscalls.h"
    >
    > main()
    > {
    >
    > char buf[BUFSIZE];
    > int n;
    > while((n = read(0,buf, BUFSIZ))> 0)
    > write(1, buf, n);
    >
    > return 0;
    >
    > }
    >
    > It is sayin BUFSIZ not declared but according to K & R 2 it is defined
    > in syscalls.h



    syscalls.h is not a standard header. And 'read' and 'write' are
    not standard library functions, neither. In fact, they're POSIX
    functions.

    --
    Hi, I'm a .signature virus, please copy/paste me to help me spread
    all over the world.

  4. Re: K & R 2 program about low level file input/ouptut not running

    broli wrote:

    > #include "syscalls.h"


    #include /* BUFSIZ */
    #include /* read, write */

    > main()


    int main(void)

    > {
    >
    > char buf[BUFSIZE];


    Surely you meant char buf[BUFSIZ];

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


+ Reply to Thread