Next, you must arrange for the serial number to be copied into the new
character array using strcpy
, for string copy,
another function from the string library. Note that the target array is
the first argument, and the source array is the second:
strcpy (serial_number, input_buffer);
The effect of strcpy
is to copy the serial number from the
input_buffer
array, which has to be big enough for serial numbers of
any conceivable length, into the serial_number
array, which is just big
enough to hold the number actually observed:
input_buffer Null character | | v v *---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*- | T | P | W | - | E | - | 7 | 8 | 3 | | | | | | | *---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*-- | | | | | | | | | | | | | | | | | | | | <-- Copy operation v v v v v v v v v v *---*---*---*---*---*---*---*---*---*---* | T | P | W | - | E | - | 7 | 8 | 3 | | *---*---*---*---*---*---*---*---*---*---* ^ | serial_number