Skip to content

Instantly share code, notes, and snippets.

@briankip briankip/ssss
Created Oct 9, 2015

Embed
What would you like to do?
int main()
{
char *str = "blablabla";
char c = 'H';
size_t len = strlen(str);
char *str2 = malloc(len + 1 + 1 ); /* one for extra char, one for trailing zero */
strcpy(str2, str);
str2[len] = c;
str2[len + 1] = '\0';
printf( "%s\n", str2 ); /* prints "blablablaH" */
free( str2 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.