Home > Archive > Unix Programming > March 2008 > K & R 2 program about low level file input/ouptut not running
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
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
| |
| WANG Cong 2008-03-13, 8:16 am |
| 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.
| |
| Robert Harris 2008-03-13, 8:16 am |
| WANG Cong wrote:
> On Thu, 13 Mar 2008 02:43:29 -0700,broli wrote:
>
>
>
> 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 <stdio.h> instead.
Robert
| |
|
| broli wrote:
> #include "syscalls.h"
#include <stdio.h> /* BUFSIZ */
#include <unistd.h> /* 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;
>
> }
|
|
|
|
|