0

我将值保存到 NXC(不是 eXactly C)中的 .csv 文件,然后在稍后的时间点调用它们。我遇到的问题是,当从单元格中调用任何负值时,它显示为 0123 而不是 -123,这会导致我所有的额外计算都失败。

当前代码是:

OpenFileRead("map.csv", fSize, count);
  until (eof == true) {
    ReadLnString(count, val);
    int lstFwd = StrToNum(val);
    NumOut(0,LCD_LINE1,lstFwd);
  }
while(true);

任何人都可以解释如何纠正这个问题,因为它现在给我带来了很大的压力。

4

1 回答 1

0

StrToNum should convert negativ numbers. Its a bit strange that an integer number starts with 0. You should also use Enhanced NBC/NXC firmware.

First: You should always clear the screen before writing some output! Use:

NumOut(0,LCD_LINE1,lstFwd, DRAW_OPT_CLEAR_LINE);

If the problem still exists try:

string val;
OpenFileRead("map.csv", fSize, count);
  until (eof == true) {
    ReadLnString(count, val);
    int lstFwd = StrToNum(val);
    if(SubStr(val, 0, 1) == "-") lstFwd *= -1; // Check if first char is "-"
    NumOut(0,LCD_LINE1,lstFwd, DRAW_OPT_CLEAR_LINE);
  }
while(true);
于 2014-05-01T19:29:20.470 回答