This program concatenation two strings using c Program .Without using library function Strcat() provided by the library file <String.h>.Here use two character pointer , they are concatenated .
Program code :
#include<stdio.h>
#include<conio.h>
void stcat(char *str1, char *str2);
void main()
{
char *str1, *str2;
clrscr();
printf("\n\n\t ENTER THE FIRST STRING...: ");
gets(str1);
printf("\n\n\t ENTER THE SECOND STRING...: ");
gets(str2);
stcat(str1,str2);
printf("\n\t THE CONCATENATED STRING IS...: ");
puts(str1);
getch();
}
void stcat (char *str1, char *str2)
{
int i = 0,len = 0;
while(*(str1+len)!='\0')
len++;
while(*(str2+i)!='\0')
{
*(str1+len) = *(str2+i);
i++;
len++;
}
*(str1+len) = '\0';
}
Program code :
#include<stdio.h>
#include<conio.h>
void stcat(char *str1, char *str2);
void main()
{
char *str1, *str2;
clrscr();
printf("\n\n\t ENTER THE FIRST STRING...: ");
gets(str1);
printf("\n\n\t ENTER THE SECOND STRING...: ");
gets(str2);
stcat(str1,str2);
printf("\n\t THE CONCATENATED STRING IS...: ");
puts(str1);
getch();
}
void stcat (char *str1, char *str2)
{
int i = 0,len = 0;
while(*(str1+len)!='\0')
len++;
while(*(str2+i)!='\0')
{
*(str1+len) = *(str2+i);
i++;
len++;
}
*(str1+len) = '\0';
}
If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
AND
If you like this article , like our Facebook like page and click +1 to support 123techguide
|