功能sprintf [英] function sprintf

查看:78
本文介绍了功能sprintf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码行:

sprintf(buf,"%20g",*(liftPtr ++))

这是什么意思? sprintf的功能是什么?

谢谢

michele

I have a code line like this:
sprintf(buf, "%20g",*(liftPtr++))
what does it mean? And what does the function sprintf do?
Thanks
michele

推荐答案

On Thu, 2004年4月1日21:31:39 +0200,Michele < MI ******** @ libero.it>写道:
On Thu, 1 Apr 2004 21:31:39 +0200, "Michele" <mi********@libero.it> wrote:
我有这样的代码行:
sprintf(buf,"%20g",*(liftPtr ++))
是什么意思? sprintf的功能是什么?
谢谢
michele


你有一本方便的图书馆参考书吗?如果没有,浏览器怎么样?

您可以在线获取图书馆设施所需的所有信息。我喜欢

Dinkumware网站:
http://dinkumware.com/manuals/reader.aspx?lib=cpp

(这是C ++lib,但包括C标题。你会在sdio.h中找到sprintf



-leor
I have a code line like this:
sprintf(buf, "%20g",*(liftPtr++))
what does it mean? And what does the function sprintf do?
Thanks
michele
Have you got a library reference book handy? If not, how about a browser?
You can get all the info you need on library facilities online. I like the
Dinkumware site:
http://dinkumware.com/manuals/reader.aspx?lib=cpp
(It''s the "C++" lib, but that includes the C headers. You''ll find sprintf
in sdio.h)
-leor




-

Leor Zolman --- BD软件--- www。 bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD Software的免费STL错误信息Decryptor at:
www.bdsoft.com/tools/stlfilt.html




" Michele" < MI ******** @ libero.it>在消息中写道

"Michele" <mi********@libero.it> wrote in message
我有这样的代码行:
sprintf(buf,"%20g",*(liftPtr ++))
是什么意思? sprintf的功能是什么?
I have a code line like this:
sprintf(buf, "%20g",*(liftPtr++))
what does it mean? And what does the function sprintf do?



您需要查找该功能。 sprintf()将字符格式化为字符串。

如果您完全使用C语言,那么您将熟悉printf()函数。

sprintf()非常相似,但字符存储而不是传递给输出




buf是目标字符串。它必须是一个char *指向足够的内存

来保存输出。

"%20g"是格式字符串。 %g告诉计算机打印一个浮点

vlaue,而20是字段宽度说明符。

*(liftPtr ++)表示取liftPtr指向的内容,这里一个浮点

数,然后将指针增加为大小效果。显然你看了一些正在打印浮点数列表的代码。


You need to look up the function. sprintf() formats characters to a string.
If you''ve used C at all you''ll be familiar with the printf() function.
sprintf() is very similar, but characters are stored instead of being passed
to the output.

buf is the destination string. It must be a char * pointing to enough memory
to hold the output.
"%20g" is the format string. %g tells the computer to print a floating-point
vlaue, and the 20 is the field width specifier.
*(liftPtr++) means take what liftPtr points to, here a floating-point
number, and then increment the pointer as a size effect. Your are obviously
looking at some code which is printing out a list of floating point numbers.


2004年4月1日星期四21:31 :39 + 0200,Michele < MI ******** @ libero.it>写道:
On Thu, 1 Apr 2004 21:31:39 +0200, "Michele" <mi********@libero.it> wrote:
我有这样的代码行:
sprintf(buf,"%20g",*(liftPtr ++))
是什么意思? sprintf的功能是什么?


哦对不起,我的意思是帮助你使用指针表达式部分。


这段代码暗示liftPtr是指向float或double(大概是

a指针指向它们中的某个数组。)让我们把它称为双倍,

因为没有太多可以继续(我''假设它是浮点类型

,因为用于显示值的%g格式转换)。


表达式的值(liftPtr ++)是

的当前(old)值指针;间接运算符(*)应用于该值,

产生指针进入该语句的双精度值

指向。


在下一行代码执行之前(我在这里简化),

liftPtr的值将增加到指向

序列。这就是++的作用,它在

操作数(后缀符号)右侧的位置是延迟的含义。增加直到

后,旧的值被抽样用作*的操作数。


有意义吗?

- leor

谢谢
michele
I have a code line like this:
sprintf(buf, "%20g",*(liftPtr++))
what does it mean? And what does the function sprintf do?
Oh sorry, I did mean to help you with the pointer expression part.

This code implies that liftPtr is a pointer to float or double (presumably
a pointer to somewhere within an array of them.) Let''s just call it double,
since there isn''t much to go on (I''m assuming it is a floating point type
because of the %g format conversion being used to display a value).

The value of the expression (liftPtr++) is the present ("old") value of
that pointer; the indirection operator (*) is applied to that value,
yielding the value of the double that the pointer goes into that statement
pointing to.

Before the next line of code executes (I''m simplifying here), the value of
liftPtr will have been incremented to point to the /next/ double in
sequence. That''s what the ++ does, and its position on the right of its
operand ("postfix" notation) is what "delays" the incrementing until after
the old value has been sampled for use as the operand to *.

Make sense?
-leor
Thanks
michele




-

Leor Zolman --- BD软件 - - www.bdsoft.com

C现场培训/ C ++,Java,Perl和Unix

C ++用户:下载BD Software的免费STL错误消息Decryptor:
www.bdsoft.com/tools/stlfilt.html


这篇关于功能sprintf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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