D
Darklight
Question taken from a book
Write a function that accepts two strings. Use the malloc()
function to allocate enough memory to hold two strings after
they have been concatenated(linked). Return a pointer to this
new string.
/* STRCAT1.C PROGRAM TO LINK TWO STRINGS TOGETHER */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char *join(char *, char *);
int main(void)
{
char str[ ] = {"hello"};
char str1[ ] = {" world!"};
char *c;
c = join(str, str1);
printf("%s\n",c);
return 0;
}
char *join(char *a, char *b)
{
char *link;
link = (char *)malloc(15 * sizeof(char));
/* or use: link = (char*) malloc(15); */
link = strcat(a, b);
return link;
}
Write a function that accepts two strings. Use the malloc()
function to allocate enough memory to hold two strings after
they have been concatenated(linked). Return a pointer to this
new string.
/* STRCAT1.C PROGRAM TO LINK TWO STRINGS TOGETHER */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char *join(char *, char *);
int main(void)
{
char str[ ] = {"hello"};
char str1[ ] = {" world!"};
char *c;
c = join(str, str1);
printf("%s\n",c);
return 0;
}
char *join(char *a, char *b)
{
char *link;
link = (char *)malloc(15 * sizeof(char));
/* or use: link = (char*) malloc(15); */
link = strcat(a, b);
return link;
}