Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
pointconcat
//g++ 7.4.0 //write a function that copies the first n bytes beginning with *s2 into the bytes beginning at the location of the first occurrence of the null character ‘\0’ after *s1, where n is the number of bytes that s2 has to be incremented before it points to the null character‘\0’; //this code is created by Rezaul Hoque on July 24,2021; contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; void cat(char *, char*); //this function is like strcat() defined in string.h; it concatenates one string at the end of the other void cat(char * s1, char* s2){ int n =4; int n2 = 4; char s3[n+n2];//a buffer array is created equal to total size of s1 and s2 int l= n-1;//l is initialized to the last element of s1 as zero-based indexing is being followed here for (int k=0;k<n;k++){ s3[k]=s1[k];//first s1 is copied into s3 } for (int k=0;k<n2;k++){ s3[l+k]=s2[k];//then s2 is copied into s3; note index of s3 is l+k; so values of s2[0],s2[1]...are copied into s3[l+0],s3[l+1] } for(int k=0;k<n+n2;k++) cout<<s3[k]; } int main(){ char s1[]="ABC"; char s2[]= "DEF"; cout<<"Before concatenation: \n"; cout<<s1<<endl; cout<<"After concatenation: \n"; cat(s1,s2); return 0; }
run
|
edit
|
history
|
help
0
Op&&^Overload
Zahra_matrix
CPP - Arrays - Ex.2
VecCrossProd
List Add v3
Test02
shifting
tAquireSignalProcessor
AVL - ith element
map_find