Problem statement
Write a program to append source string at the end of target string using user defined function.
Here don’t use standard string handling function strcat().
Program to concatenate two string without using strlen()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include<stdio.h> void ustrcat(char*,char*); int main() { char sstr[20] = "Encyclop"; char tstr[20] = "Web"; ustrcat(tstr, sstr); printf("Target string is %s", tstr); } void ustrcat(char* t, char*s) { if(*t = '\0') { while(*s != '\0') { *t = *s; s++; } } else t++; } |
Output
1 |
Target string is WebEncyclop |