Ad
  • Custom User Avatar

    Also, the amount of spaces required will differ from the original text. If you want a safe allocation, we might need to alloc (2 * strlen(text) + (strlen(text)- 1))). Because for each possible letter you are allocating 1 extra byte for safety, and 1 extra byte for space, excluding the last char(hence strlen(text - 1)). In case the string is, for example "Abcdefghijklmonpqrzx" - no spaces at all, and letters that do consume 2 bytes - this will work, whereas allocating for strlen(text) wont.