0

Please read till the end.

I have a function that loops through a character array until it finds the '\0' end character in a character array.

I want to convert the integer

int number = 128;

To a character array

char data[] = ""; // data[] = "128"  , contains '\0'

I have found several ways suggested (memcpy, itoa) but I want a conversion that adds the '\0' automatically at the end.

  • About that comment: String literals in *double quotes* in C have NUL char at end, so `"128\0"` would have 2 NUL chars. – hyde Oct 09 '19 at 15:03

1 Answers1

-1

itoa() automatically adds a null terminator. See: http://www.cplusplus.com/reference/cstdlib/itoa/

s-i-c-o
  • 1
  • 1