c question: *printf'ing arrays

Igor Mozolevsky igor at hybrid-lab.co.uk
Tue Jun 30 18:19:45 UTC 2009


2009/6/30 Alexander Best <alexbestms at math.uni-muenster.de>:
> should be stdout.
>
>
> struct Header *hdr = rom;
>
> int new_fd = open("/dev/stdout", O_RDWR);
>
> printf("SIZE: %d\n",sizeof(*hdr));
>
> write(new_fd, hdr, sizeof(*hdr));
>
> close(new_fd);

You should really be checking what open returns, opening /dev/stdout
for reading is a bit weird not sure if that would work, and most
likely it's already open... Just use fileno(...):-

#include <unistd.h>
#include <stdio.h>

int main(void) {
  write(fileno(stdout), "Hello world!\n", 13);
  return 0;
}

Cheers,
--
Igor


More information about the freebsd-hackers mailing list