News for hackers. Stuff that matters.
Re:Interviewing programmers: coding test example explained by js2 on Thursday June 03, 2010 @09:53AM (#1401280)
Yes, C strings are \0 terminated and that is what you'd end up with.

Memory management is between you, malloc() and free().

Assuming this were malloc()d memory, if you wanted to free up the unused bytes, you'd probably:

  char *condensed = strdup(z_terminated);
  if (condensed)
    free(z_terminated);
  else
    // out of memory
Re:Interviewing programmers: coding test example explained by cperciva on Thursday June 03, 2010 @10:26AM (#1401388)
Using realloc would be better, since it allows the memory allocator the option of not copying the string.
Re:Interviewing programmers: coding test example explained by js2 on Thursday June 03, 2010 @10:59AM (#1401479)
Indeed. I wasn't sure you could realloc to a smaller block. Good to know.