开发者

sending a file to stdout in C

开发者 https://www.devze.com 2023-02-14 21:38 出处:网络
I need to write a plain PPM file to the standard output. I have it creating the PPM file and everything, I just cannot f开发者_StackOverflowigure out how to get it to send it to the standard output.

I need to write a plain PPM file to the standard output. I have it creating the PPM file and everything, I just cannot f开发者_StackOverflowigure out how to get it to send it to the standard output.

Any help you can provide is greatly appreciated,


you should look up these functions: open, read, write, close.

then your code will look something like:

#include <unistd.h>
int fd = open("/path/to/file", O_RDONLY);
char buf[1024];
int buflen;
while((buflen = read(fd, buf, 1024)) > 0)
{
    write(1, buf, buflen);
}
close(fd);

please keep in mind this is untested.


fwrite(blah,size_blah,1,stdout);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号