多头的 printf

发布于 2024-12-14 23:01:05 字数 444 浏览 1 评论 0原文

我实现了 myPrintf 函数:

int myPrintf(const char* format,...)
{
    va_list args;
    va_start(args, format);
    int ret = vprintf (format, args);
    fflush(stdout);
    va_end (args);
    return ret;
}

当我使用 format = "%ld,%ld" 运行该函数时 作为字符集的 args 表示形式为 78,97,188,0,0,0,0,0,120,10,227,5,0,0,0,0 打印到 stdout 的输出是 12345678,0。而不是 12345678,98765432。 可能是什么问题?如何解决?

I implemented myPrintf function:

int myPrintf(const char* format,...)
{
    va_list args;
    va_start(args, format);
    int ret = vprintf (format, args);
    fflush(stdout);
    va_end (args);
    return ret;
}

When I run the function with format = "%ld,%ld"
and the args representation as set of chars is 78,97,188,0,0,0,0,0,120,10,227,5,0,0,0,0
the output printed to stdout is 12345678,0.Instead of 12345678,98765432.
What could be the problem?And how could it be solved?

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

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

发布评论

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

评论(1

煮酒 2024-12-21 23:01:05

因为,就像在 ideone 上一样,您的 long 是 32 位
http://ideone.com/jjafU

如果您使用 64 位的 "%lld" -位值,它按您的预期工作
http://ideone.com/BYTaa

Because, like on ideone, your longs are 32 bits
http://ideone.com/jjafU

If you use "%lld" for 64-bit values, it works as you expect
http://ideone.com/BYTaa

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文