c concatenate strings
char str[80];
strcpy(str, "these ");
strcat(str, "strings ");
strcat(str, "are ");
strcat(str, "concatenated.");
c concatenate strings
char str[80];
strcpy(str, "these ");
strcat(str, "strings ");
strcat(str, "are ");
strcat(str, "concatenated.");
concatenate two strings in c
#include <stdio.h>
#include <string.h>
int main()
{
char a[1000], b[1000];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
strcat(a, b);
printf("String obtained on concatenation: %s\n", a);
return 0;
}
c concatenate and allocate string
// null protected
char* strconcat(char *str1, const char *str2)
{
char *str = NULL;
size_t len1 = 0;
size_t len2 = 0;
if (str1)
len1 = strlen(str1);
if (str2)
len2 = strlen(str2);
if (!(str = calloc(sizeof(char), (len1 + len2 + 1))))
return NULL;
if (str1)
memcpy(str, str1, len1);
if (str2)
memcpy(str + len1, str2, len2);
return (str);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us