从NXC中的文件返回的负值 [英] Negative values returned from file in NXC

查看:57
本文介绍了从NXC中的文件返回的负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将值保存到NXC(不是XC)中的.csv文件中,然后在以后的某个时间点调用它们。我遇到的问题是,从单元格中调用任何负值时,它显示为0123而不是-123,这使我所有其他计算都无法进行。

I am saving values to a .csv file in NXC(Not eXactly C) and then calling on them ata later point in time. The problem I am having is when calling any negative values back from a cell it is displayed as 0123 instead of -123 which is throwing all my additional calculations off.

当前代码是:

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

谁能解释如何纠正此问题,因为它现在给我造成了很大压力。 / p>

Can anyone explain how to rectify this issue as it is causing me a great deal of stress now.

推荐答案

StrToNum应该转换负数。整数从0开始有点奇怪。您还应该使用增强型NBC / NXC固件。

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);

这篇关于从NXC中的文件返回的负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆