sprintf的(),而不使用C尾随零空间 [英] sprintf() without trailing null space in C

查看:190
本文介绍了sprintf的(),而不使用C尾随零空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有用C的sprintf()函数,而它在其输出的末尾加一个'\\ 0'字符的方法吗?我需要写在一个固定的宽度字符串中间格式的文本。

Is there a way to use the C sprintf() function without it adding a '\0' character at the end of its output? I need to write formatted text in the middle of a fixed width string.

推荐答案

有没有办法告诉的sprintf()不写结尾空。你可以做的是使用的sprintf()来写一个临时字符串,然后像函数strncpy()来仅复制所需的字节数。

There is no way to tell sprintf() not to write a trailing null. What you can do is use sprintf() to write to a temporary string, and then something like strncpy() to copy only the bytes that you want.

这篇关于sprintf的(),而不使用C尾随零空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆