ASCIIZToMaxLenStr
Converts an ASCIIZ (NULL-terminated) string to a length-preceded string that is not longer than the specified maximum length
#include <nwstring.h> int ASCIIZToMaxLenStr ( char *lenString, char *ASCIIZstring, int maximumLength);
The following table lists return values and descriptions.
A length-preceded string has the length of the string in the first byte, followed by the characters in the string; it cannot exceed 255 characters. If the ASCIIZstring string is longer that 255 characters, this function returns EFAILURE, and lenString contains maximumLength characters. The remaining characters of the ASCIIZstring are not copied to lenString.
Since length-preceded strings only have one byte to store the size of the string, the maximum size of the string is 255. Passing a maximum size larger than 255 produces unpredictable results.
#include <nwstring.h> #include <errno.h> main() { char srcString[256]; char destString[256]; int ccode; int maxSize; strcpy(srcString,"This is the message"); maxSize = 100; ccode = ASCIIZToMaxLenStr(destString, srcString, maxSize); if(ccode == ESUCCESS) printf("The string fits.\n"); else printf("The string was too long to fit in the allotted space.\n"); }