use warnings;
use strict;
my $text = 'hello ' x 30;
printf "%-20s : %s\n", 'very important text', $text;
Run Code Online (Sandbox Code Playgroud)
这个脚本的输出看起来更像这样:
very important text : hello hello hello hello
hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello
...
Run Code Online (Sandbox Code Playgroud)
但我想要一个像这样的输出:
very important text: hello hello hello hello
hello hello hello hello
hello hello hello hello
...
Run Code Online (Sandbox Code Playgroud)
我忘了提到:文本应该有一个开放的结尾,因为文本行的右端应该对应于终端的大小.
我怎样才能更改脚本以达到目标?
考虑以下代码:
typedef int64_t Blkno;
#define BLKNO_FMT "%lld"
printf(BLKNO_FMT, (Blkno)some_blkno);
Run Code Online (Sandbox Code Playgroud)
这在x86上运行良好.在x64和int64_t实际上是一个long,而不是一个long long,并且当long和long long是在x64相同的尺寸,编译器会生成一个错误:
src/cpfs/bitmap.c:14:警告:格式'%lld'需要类型'long long int',但参数6的类型为'Blkno'
printf我通过64位类型?#define像BLKNO_FMT上面那样使用?我正在尝试快速学习GWT作为新项目的一部分.我发现GWT没有实现Java的String.format()函数,因此没有类似printf()的功能.我知道Javascript存在一些printf()实现,所以我想我可以将其中一个作为GWT Javascript Native Interface函数粘贴.我遇到了问题,并决定我最好确保varargs值正确传递.这就是事情变得丑陋的地方.首先,一些示例代码:
// From Java, call the JSNI function:
test("sourceString", "params1", "params2", "params3");
....
public static native void test(Object... params) /*-{
// PROBLEM: this kills GWT!
// alert(params.length);
// returns "function"
alert(typeof(params));
// returns "[Ljava.lang.Object;@b97ff1"
alert(params);
}-*/;
Run Code Online (Sandbox Code Playgroud)
GWT文档声明"从Java调用varargs JavaScript方法将导致被调用者接收数组中的参数".我想这意味着我至少可以检查params.length,但访问它会抛出一个包含在UmbrellaException中的JavascriptException,没有真正的信息.当我做"typeof(params)"时,它返回"function".好像这不够奇怪,如果我检查params的字符串值,它会返回看似是Java引用的字符串版本.
所以,我想我在这里问了几个不同的问题:
1)GWT/JSNI varargs如何实际工作,我是否需要做一些特殊的事情来传递价值观?
2)这里到底发生了什么?
3)有没有更简单的方法在GWT应用程序中获得printf() - 样式格式?
我发现这篇文章解释了如何设置条件断点以打破任何printf函数.在XCode中实现类似功能的过程是什么?目的显然是调试器停止何时何地尝试在控制台中输出任何内容.
我已经使用fprintf了一段时间了,我想问一个问题.这条fprintf线的等价物是什么:
fprintf(OutputFile, "%s", "SomeStringValue");
Run Code Online (Sandbox Code Playgroud)
用ofstream?
如何使用"%s" ofstream是我真正想知道的.如何获取下一个参数并将其打印为字符串?
我正在跟随工会
union data {
uint64_t val;
struct{
....
}
};
Run Code Online (Sandbox Code Playgroud)
我有一个功能
func(union data mydata[])
{
printf("%llu",(uint64_t)mydata[0]); // Here is the error
}
Run Code Online (Sandbox Code Playgroud)
当我编译此代码时,它给出了以下错误
error: aggregate value used where an integer was expected
Run Code Online (Sandbox Code Playgroud) 我真的不明白这一点.也许有人可以解释我.我想知道dataInput中有多少个元素.我在C编程
void Calibrate_data(float* dataInput)
{
int dataSize = sizeof(*dataInput)/sizeof(float);
printf("%i and %i",sizeof(*dataInput)/sizeof(float),dataSize);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
1 and 10
Run Code Online (Sandbox Code Playgroud) 我的程序在几个平台上运行.其中,Windows CE.目前,sprintf被广泛使用,导致缓冲区溢出等问题很多.我想用snprintf调用替换它们.对于Visual Studio,我发现了这个问题,它解决了问题的win32部分:
但我不能让它适用于Windows CE,因为函数_vsnprintf_s和_vscprintf,以及常量_TUNCATE都不可用.有人知道在Windows CE上复制snprintf(linux)行为的方法吗?
我有一个用ASCII打印的游戏板,我希望最终看起来像这样
___
3 ___/ 1 \___ ___
___/ 2 \___/ 2 \/ 3 \
2 / 1 \___/ 3 \___/\___/___
\___/ 2 \___/ / 2 \
1 / 1 \___/ 1 \___ \___/
\___/ 2 \___/ 2 \
0 \___/ \___/
1 2 3 4
Run Code Online (Sandbox Code Playgroud)
地图沿x轴和y轴分布,地图的大小也是固定的.要打印的数字都存储在2d数组中.如上所示,其中一些也可能是空的.这是我试图做的事情.map-> sizeX和map-> sizeY给出地图的X轴和y轴的大小.如果该块中的数字为0,则表示该块不存在,我们不打印它.任何帮助将非常感激.
void printMap(struct Map *map) {
for (int i = 0; i < map->sizeX; ++i) {
for (int k = 0; k < map->sizeX && i == 0; ++k)
printf(" ___ ");
printf("\n"); …Run Code Online (Sandbox Code Playgroud)