wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/String

Version 5 (modified by Don Wilson, 14 years ago) ( diff )

--

String Functions

The 825 can be programmed using C/C++ character array strings and the standard C library such as:

char szMsg[10];
char szID[10];
strcpy(szID, "123");
sprintf(szMsg, "ID: %s", szID);
PrintLCD(szMsg);

The is the traditional C programming way of handling strings. The C language has no true string type; strings are just arrays of characters. This is very fast and efficient because the compiler just generates code to read and write the memory directly as it is coded. However, there is no automatic checking that pointers point to valid memory, or to prevent writing beyond memory that is allocated. It is very easy to crash an 825 indicator by programming this code incorrectly.

The 825 also supports a newer C++ string type std::string. Using std::string does not require as much diligence from the programmer. The string will automatically allocate more memory and grow if needed by an assignment. The operations are also more like the BASIC language so this is helpful for programmers who are not as skilled in C/C++.

string strMsg;
strMsg = "ID: ";
string strID = "123";
strMsg = strMsg + strID;
PrintLCD(strMsg);

The 825 standard library functions now accept string parameters. We are now recommending using strings in application programs as much as possible to reduce the possibility of pointers to invalid memory, or overflow bugs.

For more information about std::strings refer to: http://www.cplusplus.com/reference/string/string/

To further help with string operations some additional functions are now provided in the 825 library.

Note: See TracWiki for help on using the wiki.