One of the answers to Why do you not use C for your web apps? contains the following:
For the C crap example below:
const char* foo = &quo
#include
#include
int
main(int argc, char *argv[])
{
char *str1 = "foo";
char *str2 = "bar";
char ccat[strlen(str1)+strlen(str2)+1];
strncpy(&ccat[0], str1, strlen(str1));
strncpy(&ccat[strlen(str1)], str2, strlen(str2));
ccat[strlen(str1)+strlen(str2)+1] = '\0';
puts(str1);
puts(str2);
puts(ccat);
}
this code concatenates str1 and str2 without the need for malloc, the output should be:
foo
bar
foobar