How to Determine the Length of a String

How to Determine the Length of a String - the length of the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
How to Determine the Length of a String. .. A C string can be created from a binary data type by using the sprintf() function. By including the standard C I/O library ( "#include <stdio.h> " and defining a character array of sufficient size for the string, the pen coordinates can be converted from binary to ASCII. #include <stdio.h> char buffer[16]; ... sprintf(buffer, "%d", x); The length of a C string can be determined empirically by checking the size of the number. (ie, greater than 9999 = 5, greater than 999 = 4, etc.) Or, you can " #include <string.h> " and call the function: int strlen(const char *); The strlen() function computes the number of bytes in the string to which the parameter points, not including the terminating null byte. The strlen() function returns
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the length of the C string; no return value is reserved to indicate an error. The optional length specification parameter of the printf and sprintf functions can be used (when enabled) to create a string of a specific length by including the size between the &quot;%&quot; and the conversions specification. sprintf(buffer, &quot;%10d&quot;, x); // convert x to a string of 10 characters NOTE: To enable the full functionality of the printf and sprintf functions, select your CCS project, follow the drop-down menus to Library Function Assumptions (Project-&gt;Properties-&gt;C/C++ Build), and select full Level of printf support required (--printf_support). i.e....
View Full Document

Page1 / 2

How to Determine the Length of a String - the length of the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online