Reply to post:

Oracle pours a mug o' Java 11 for its addicts, tips pot of Binary Code License down the sink

Brewster's Angle Grinder Silver badge

I presumed the work involved in string reallocation would be the same for both approaches and so excluded the substring step for clearer exposition.

But, because I've not had to code pure C in a long time and there is a certain delight in being able to do this stuff, I think it should be:

char* res = malloc(strlen(str)+1);

return res != NULL ? strcpy(res,str) : NULL

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon