#include<iostream.h>
#include<string.h>
// with pointers
void myStrCat1(char *s1, const char *s2)
{
// boro jelo taa be sefre paayaane
// reshte beresi
while (*s1)
s1++;
// boto jelo taa be sefre paayane reshteye
// s2 beresi, copy kon
while (*s2) {
*s1 = *s2;
s2++;
s1++;
}
// sefre payan reshte be s1 ezaafe ko
*s1 = '\0';
}
// with arrays
void myStrCat2(char s1[], const char s2[])
{
int i, j;
for (i=0 ; s1[i] ; i++);
for (j=0 ; s2[j] ; i++,j++)
s1[i] = s2[j];
s1[i] = '\0';
}
// with arrays, AND strlen
void myStrCat3(char s1[], const char s2[])
{
int i, j;
i = strlen(s1);
for (j=0 ; s2[j] ; i++,j++)
s1[i] = s2[j];
s1[i] = '\0';
}
void main ()
{
char esm1[80] = "ali";
char esm2[80] = "gholi";
myStrCat1(esm1, esm2);
myStrCat2(esm1, esm2);
myStrCat3(esm1, esm2);
cout << esm1 << endl;
}