How can I end a string in C? I made a function to connect 2 strings and make one. I read I should end string with '\0' but how to do this with declaration like this?
char* string1= "House";
char* string2= "is big";
Create an array big enough to fit both strings plus a single terminator. Copy the first string into the array. Concatenate the other string using strcat
.
Try this method
char* concat(const char *s1, const char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);
strcpy(result, s1);
strcat(result, s2);
return result;
}