Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 12 Feb 2011, 12:40
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
Post
by h-g-t » 12 Feb 2011, 13:22
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
Post
by HaWe » 12 Feb 2011, 13:31
as I just found out, this works:
Code: Select all
s=FormatNum("%d", ibuf);
s= s +";" ;
but this not:
Using NumToStr instead of FormatNum is the same issue.
hergipotter
Posts: 48 Joined: 12 Jan 2011, 18:40
Contact:
Post
by hergipotter » 12 Feb 2011, 17:33
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
Post
by HaWe » 12 Feb 2011, 17:45
yes, it does
;)
afanofosc
Site Admin
Posts: 1256 Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:
Post
by afanofosc » 14 Feb 2011, 15:53
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
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 14 Feb 2011, 16:21
thank you John for the clarification!
:)
Users browsing this forum: No registered users and 2 guests