string concatenation:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *str_contact (const Char *,const char *);
Char *str_contact (const char *str1,const char *str2)
{
char *result = (char*) malloc (strlen (str1) + strlen (str2) + 1);
if (!result)
{
printf ("Error:malloc failed in concat! \ n ");
Exit (exit_failure);
}
char *temp = result;
while (*str1!= ' ")
{
*result++ = *str1++;
}
while ((*result++ = *str2)!= ' ")
{
;}
return
temp;
}
int main (void)
{
char *ch1 = ' string_ ';
char * CH2 = "_contact";
char *result = NULL;
result = Str_contact (CH1,CH2);
Print ("result =%s\n", result);
Free (result);
result = NULL;
return 0;
}
String copy:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Char *strcpy (char *dst, const char *src)
{
assert (*dst!= NULL && *src!=null);
char *temp = DST;
while (*src!= ' ")
{
*dst++ = *src++;
}
*DST = ' n ';
return temp;
}
int main (void)
{
char *ch1 = ' str_cpy ';
char *ch2;
Char *result = strcpy (ch2,ch1);
printf ("result =%s\n", result);
Free (result);
result = NULL;
return 0;
}