Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c中同时使用字符串和整数_C - Fatal编程技术网

在c中同时使用字符串和整数

在c中同时使用字符串和整数,c,C,c版本: text_layer_set_text(hello_layer, "Last:"+x+" min"); c(适用于pebble[可编程手表])版本: text_layer_set_text(&hello_layer, **WHAT SHOULD I PUT HERE?**); 我也看到了: sprintf和friends需要malloc,这在 WatchFaceSDK。它们也是巨大的功能,将远远超过 Pebble应用程序的可用空间

c版本:

text_layer_set_text(hello_layer, "Last:"+x+" min");
c(适用于pebble[可编程手表])版本:

 text_layer_set_text(&hello_layer, **WHAT SHOULD I PUT HERE?**);
我也看到了:

sprintf和friends需要malloc,这在 WatchFaceSDK。它们也是巨大的功能,将远远超过 Pebble应用程序的可用空间

“我建议尝试一些类似于手工实现的东西。 任何避免动态分配内存的itoa都应该做到这一点。 此外,如果您需要,您应该能够简化您的实现 只对以10为基数打印数字感兴趣


您需要使用
sprintf
连接字符串/整数,如下所示:

 char buffer[100];
 sprintf(buffer, "Last:%d min", x);
 text_layer_set_text(&hello_layer, buffer);
编辑:

对于Pebble,似乎有一个标题
mini printf.h
,它定义了
mini\u snprintf
。因此,请尝试一下:

#include "mini-printf.h"

mini_snprintf(buffer, sizeof(buffer), "Last:%d min", x);

你考虑过C教程吗?我试过使用sprintf,这是我一直使用的,但它在我的设备上不起作用。实际上我是一个C++程序员,不是C,所以我只是想找到别的方法,因为我不能使用Sprint。f@user2596732您必须包括stdio.hIf还有另一种方式我会欣然接受,它只是说:构建失败,我把全部错误放到topic@user2596732
text\u layer\u set\u text
的原型是什么?我只是假设
text\u layer\u set\u text(不管类型是什么&hello\u layer,char*)
@user2596732您可能还没有包括stdio.hI确实看到了这样的情况:sprintf和friends需要malloc,watchface SDK不支持它。它们也是巨大的功能,远远超出了Pebble应用程序的可用空间。我建议尝试一些类似于手动实现的东西。任何避免动态分配内存的itoa都应该做到这一点。此外,如果您只对以10为基数打印数字感兴趣,则应该能够简化实现。@user2596732 pebble似乎有一个
mini_snprintf
函数。检查我的编辑。