如何使用sprintf附加字符串? [英] How to append strings using sprintf?

查看:82
本文介绍了如何使用sprintf附加字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 sprintf 时遇到了一个严重的问题.

I am facing a serious issue with sprintf.

假设我的代码片段是:

sprintf(Buffer,"Hello World");
sprintf(Buffer,"Good Morning");
sprintf(Buffer,"Good Afternoon");
.
.
.

几百次冲刺......

Some hundred sprints....

如果我喜欢这个,它就会被覆盖.

If I do like this, it's getting overwritten.

如何避免使用 sprintf 覆盖?如果我在最后给出 printf,我想查看所有行.

How can I avoid overwriting using sprintf? If I give a printf at the end I want to see all the lines.

推荐答案

您需要:

sprintf(Buffer,"Hello World");
sprintf(Buffer + strlen(Buffer),"Good Morning");
sprintf(Buffer + strlen(Buffer),"Good Afternoon");

当然,您的缓冲区需要足够大.

and of course you need your buffer to be big enough.

这篇关于如何使用sprintf附加字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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