【问题标题】:NXC StrToNum always returns 0NXC StrToNum 始终返回 0
【发布时间】:2014-09-08 21:45:46
【问题描述】:

我对 NXC 有一个奇怪的问题。我尝试从 android 手机接收消息并将字符串转换为 int 值。 问题是它总是0 那只是一个测试程序。所以很奇怪^^

    // MASTER
#define INBOX 0
string tmps1 = "";
string tmps2 = "";
int size;
char ret;
byte tmpi;

bool btn = false;
string msg;
long number;
int countMSG = 0;
int sudoku[9][9];
task main ()
{
  SetSensorTouch(IN_3);
  SetSensorMode(IN_3, SENSOR_MODE_BOOL);

  TextOut (0 , LCD_LINE1 ," Master Receiving ",true );

  while (btn == 0)
  {

   if(ReceiveMessage(INBOX ,true , msg) == NO_ERR)
   {
    TextOut (0, LCD_LINE3 ,msg, false);
    break;
   }
   Wait(250);
   btn = Sensor(IN_3);
  }
  for(int i = 0; i < 9; i++)
  {
     tmps1 = SubStr(msg, i, 1);

     sudoku[i][0] = StrToNum(strcat(tmps1, "\n"));

     TextOut(i*6, LCD_LINE4, tmps1, false);
     NumOut(i*6, LCD_LINE5, sudoku[i][0], false);
     Wait(1000);
  }

  Wait(2500);
 }

【问题讨论】:

  • 您传递给 StrToNum 的字符串是什么? StrToNum 仅将字符串类型的实际数字(1,2,3,4...)转换为整数类型。

标签: android nxt lego nxc


【解决方案1】:

数独[9][9] 是问题所在。 nxc 中没有二维数组 :) 我把它替换为

int sudoku[81];

现在可以正常使用了!

【讨论】:

  • 你能提供更多的上下文吗?
猜你喜欢
  • 2018-12-10
  • 1970-01-01
  • 2017-09-05
  • 2019-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多