使用带有非空终止字符串的 printf [英] Using printf with a non-null terminated string

查看:17
本文介绍了使用带有非空终止字符串的 printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个不是 null 终止的字符串,并且你知道它的确切大小,那么如何在 C 中使用 printf 打印该字符串?我记得有这样的方法,但我现在找不到......

Suppose you have a string which is NOT null terminated and you know its exact size, so how can you print that string with printf in C? I recall such a method but I can not find out now...

推荐答案

printf有一个可能,它是这样的:

There is a possibility with printf, it goes like this:

printf("%.*s", stringLength, pointerToString);

无需复制任何东西,无需修改原始字符串或缓冲区.

No need to copy anything, no need to modify the original string or buffer.

这篇关于使用带有非空终止字符串的 printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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