简体   繁体   English

sprintf,printf和格式说明符

[英]sprintf, printf and format specifiers

I'm having trouble understanding what this line of code does: 我在理解这一行代码的功能时遇到了麻烦:

    sprintf(obj, "%s.o", root);

obj and root are both character buffers, from what I read root is basically copied to obj? obj和root都是字符缓冲区,据我所知,root基本上是复制到obj的? I'm not sure what "%so" is doing. 我不确定“%so”在做什么。 %s is to specify a String but the .o? %s是要指定一个字符串,但.o是?

thanks for any help 谢谢你的帮助

The %s will be replaced with the contents of root , and followed by the .o part of the string, which is just an "additional" text. %s将替换为root的内容,然后替换字符串的.o部分,这只是一个“附加”文本。 For example, if root has "file", obj will be set to "file.o". 例如,如果root具有“ file”,则obj将设置为“ file.o”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM