You should, however, anticipate that serial numbers may get longer, or may
become variable in length. Such anticipation requires you to measure the
length of the serial number lying in the input_buffer
array so that you
can construct a new character array that is just the right size. To
measure the length of a string, such as the serial number, you can use a
function supplied by C++'s string-handling library, which you announce
your intention to use through the following declaration:
#include
The string-handling function that you need is strlen
, for
string length:
strlen(input_buffer)
Because strlen
returns the number of characters in a string, you
need to add 1, to account for the null character, when you create a new
array:
new char[strlen(input_buffer) + 1]