Here I tried implementing strcat
function in C. Problem is that when I am printing the source string it is showing me "hyam"
not "shyam"
#include <stdio.h>
#include <string.h>
char *fun(char *target, const char *source) {
printf("%s\n", source);
int x = strlen(target);
while (*source != '\0') {
*(target + x++) = *source++;
}
*(target + x) = '\0';
return target;
}
int main() {
char target[] = "ram";
char source[] = "shyam";
fun(target, source);
printf("%s\n", target);
printf("%s", source);
return 0;
}
Here in last line of output hyam
is shown but it should be shyam
.
shyam
ramshyam
hyam