 | Dick Swan wrote: I've tested the code. The string functions -- strcpy, strcmp, strcat -- behave as exepected. The anomoly is in the print to LCD functions which does not behave as you expected.
The difficulty is that ROBOTC does not support VA_ARG style variable lists of procedure parameters. And C is a little inconsistent on how these are supported. 1. For short, int, long and float parameter types, C stores the value of the parameter on the parameter "stack". 2. For char parameter types, C stores a pointer to the parameter on the stack.
Most programmers will not use arrays of chars and instead will use ROBOTC's built-in (and memory leak, and bad pointer safe) "string" variable.
If you want to exact C-style formating, then change the definition of the "NxtDisplayTextLine" built-in function in the file RobotCIntrinsics.c. Change the existing definition to the attached.
One side effect of this change is that "%d" formating will not work with "byte" or "char" variables -- just like ANSI C. You have to cast to a short or int first. This is one of the reasons that this will not be a universal change in ROBOTC.
Here's the revised definitions.
#define DisplayTextLine(fmtType, type1, ref1, type2, ref2, default2)\ intrinsic void nxtDisplayTextLine(const int nLineNumber, const string &sFormatString, const type1 &parm1, const type2 &parm2 default2)\ asm(opcdNxtLCDDisplay, byte(nxtDsplyDrawTextLineVarVarFmtSpec), variable(nLineNumber),\ ref1(parm1), ref2(parm2),\ byte(fmtType), variableRefString(sFormatString))
DisplayTextLine(StringString,byte, variableRefByte, byte, variableRefByte, ); DisplayTextLine(StringShort, byte, variableRefByte, short, variableRefWord, ); DisplayTextLine(StringLong, byte, variableRefByte, long, variableRefLong, ); DisplayTextLine(StringFloat, byte, variableRefByte, float, variableRefFloat, ); DisplayTextLine(StringString,byte, variableRefByte, string, variableRefString, ="");
DisplayTextLine(ShortString, short, variableRefWord, byte, variableRefByte, ); DisplayTextLine(ShortShort, short, variableRefWord, short, variableRefWord, ); DisplayTextLine(ShortLong, short, variableRefWord, long, variableRefLong, ); DisplayTextLine(ShortFloat, short, variableRefWord, float, variableRefFloat, ); DisplayTextLine(ShortString, short, variableRefWord, string, variableRefString, ="");
DisplayTextLine(LongString, long, variableRefLong, byte, variableRefByte, ); DisplayTextLine(LongShort, long, variableRefLong, short, variableRefWord, ); DisplayTextLine(LongLong, long, variableRefLong, long, variableRefLong, ); DisplayTextLine(LongFloat, long, variableRefLong, float, variableRefFloat, ); DisplayTextLine(LongString, long, variableRefLong, string, variableRefString, ="");
DisplayTextLine(FloatString, float, variableRefFloat, byte, variableRefByte, ); DisplayTextLine(FloatShort, float, variableRefFloat, short, variableRefWord, ); DisplayTextLine(FloatLong, float, variableRefFloat, long, variableRefLong, ); DisplayTextLine(FloatFloat, float, variableRefFloat, float, variableRefFloat, ); DisplayTextLine(FloatString, float, variableRefFloat, string, variableRefString, ="");
DisplayTextLine(StringString,string, variableRefString, byte, variableRefByte, ); DisplayTextLine(StringShort, string, variableRefString, short, variableRefWord, ); DisplayTextLine(StringLong, string, variableRefString, long, variableRefLong, ); DisplayTextLine(StringFloat, string, variableRefString, float, variableRefFloat, ); DisplayTextLine(StringString,string, variableRefString, string, variableRefString, ="");
#undef DisplayTextLine If you want to obtain C-style form |  |