CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Created by Ramisa Fariha
#include <cstring>
#include <iostream>
using namespace std;
void cat(char*, const char*);
int main()
{
const char s[] = "ABCDEFG";
// needs to be enough size to hold 's' when it is added
char ss[20] = "ZZZZZZZZZZ";
cout << " s = [" << s << "], ss = [" << ss << "]\n";
cat(ss,s);
cout << " s = [" << s << "], ss = [" << ss << "]\n";
}
void cat(char* s1, const char* s2)
{
// copy length-of-s2 characters from s2 into: s1 + strlen(s1) = the last index (having '\0') of s1
strncpy(s1 + strlen(s1), s2, strlen(s2) + 1);
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run