在 C 中将文件发送到 stdout

发布于 2024-10-20 15:38:42 字数 85 浏览 3 评论 0原文

我需要将纯 PPM 文件写入标准输出。我让它创建了 PPM 文件和所有内容,我只是不知道如何让它发送到标准输出。

非常感谢您提供的任何帮助,

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

Any help you can provide is greatly appreciated,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦屿孤独相伴 2024-10-27 15:38:42

你应该查找这些函数:open阅读, 写入关闭

那么您的代码将类似于:

#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);

请记住这是未经测试的。

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.

独闯女儿国 2024-10-27 15:38:42
fwrite(blah,size_blah,1,stdout);
fwrite(blah,size_blah,1,stdout);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文