Page 1 of 1

NXC: compile error using FormatNum

Posted: 12 Feb 2011, 12:40
by HaWe
I get a compile error using FormatNum:

Code: Select all

int ibuf;
string s;
s=FormatNum("%d", ibuf)+";" ;
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 98
# s=FormatNum("%d", ibuf)+"
#----------------------------------------------------------
what's wrong?

Re: NXC: compile error using FormatNum

Posted: 12 Feb 2011, 13:22
by h-g-t
Are you using the enhanced firmware?

int ibuf;
string s;
s=FormatNum("%d", ibuf)+";" ;

Should that not be :-
int ibuf;
string s;
s=StrCat(FormatNum("%d", ibuf),";" );

Just getting used to this C-based stuff so apologise if this is not helpful.

Re: NXC: compile error using FormatNum

Posted: 12 Feb 2011, 13:31
by HaWe
as I just found out, this works:

Code: Select all

s=FormatNum("%d", ibuf);
s= s +";" ;
but this not:

Code: Select all

s=FormatNum("%d", ibuf)+";" ;
Using NumToStr instead of FormatNum is the same issue.

Re: NXC: compile error using FormatNum

Posted: 12 Feb 2011, 17:33
by hergipotter
I don't think there's a "+"-Operator for strings in nxc, is it?

Did you try it as h-g-t suggested?

Code: Select all

s=FormatNum("%d", ibuf);
s= s +";" ;
Does this really work as expected?

Re: NXC: compile error using FormatNum

Posted: 12 Feb 2011, 17:45
by HaWe
yes, it does
;)

Re: NXC: compile error using FormatNum

Posted: 14 Feb 2011, 15:53
by afanofosc
NXC supports string concatenation using + in some limited cases. IIRC, that is only when you have a string variable and/or constant and the + sign.

Code: Select all

string a, b, c, d;
a = "123";
b = "456";
c = "789";
d = a + b + c + "0-=";
This will compile and work correctly but the NXC compiler does not currently support using the + for string concatenation in any other situation.

John Hansen

Re: NXC: compile error using FormatNum

Posted: 14 Feb 2011, 16:21
by HaWe
thank you John for the clarification!
:)