Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 36
    Don't forget to free name_with_extension! Commented Feb 7, 2010 at 21:04
  • 3
    Can you please write const char *name, *extension? A string literal is not a char *. Commented Feb 7, 2010 at 22:03
  • 11
    A little new to C but what is up with the +1+4 in malloc(strlen(name)+1+4) I am guessing the +4 is the 4 extra chars but what is the +1? Commented Jun 3, 2013 at 20:38
  • 13
    The +1 is to account for the null terminator at the end of the string Commented Oct 15, 2013 at 1:10
  • @lopsided98 why isn't sizeof(char) used that actual byte count? e.g. malloc(strlen(name) + 4 * sizeof(char) + 1) Commented Jan 3, 2017 at 13:47