NXC: compile error using FormatNum

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: compile error using FormatNum

Post 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?
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC: compile error using FormatNum

Post 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.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: compile error using FormatNum

Post 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.
hergipotter
Posts: 48
Joined: 12 Jan 2011, 18:40
Contact:

Re: NXC: compile error using FormatNum

Post 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?
link to my youtube channel under my avatar!
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: compile error using FormatNum

Post by HaWe »

yes, it does
;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: compile error using FormatNum

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: compile error using FormatNum

Post by HaWe »

thank you John for the clarification!
:)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 7 guests