字符串连接C问题

时间:2015-08-15 17:15:44

标签: string arduino concatenation particles

我试图将多个整数变量连接成一个字符串,这样我就可以将它作为csv发送到另一个程序。但是,我无法获得字符串。你能仔细检查这段代码以确保它是正确的吗?

这适用于拥有自己的String库的Spark / Particle设备。唯一类型的"字符串"我可以返回一个字符串类型,这就是我这样做的原因......

void updatePresetVar(void) {
    String s = String();
    int integer = getGrind1;
    String integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getDuration1;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getWeight1;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getGrind2;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getDuration2;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getWeight2;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getGrind3;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getDuration3;
    integer_string = String(integer);
    s = String(s + integer_string);
    s = String(s + ",");

    integer = getWeight3;
    integer_string = String(integer);
    s = String(s + integer_string);

    presets = String(s);
}

编辑:有时我得到以下输出:

�[,或@ [,或P

0 个答案:

没有答案