Write a C program to concatenate two strings using pointers.

Program Code:
#include<stdio.h>
#define SIZE 20
void concat(char *,char *);
int main()
{
char string1[SIZE]="\0",string2[SIZE]="\0";
printf("Enter String 1:\n");
gets(string1);
printf("Enter String 2:\n");
gets(string2);
concat(string1,string2);
return 0;
}
void concat(char *str1,char *str2)
{
char *conc=str1;
while(*str1!='\0')
str1++;
*str1=' ';
++str1;
while(*str2!='\0')
{
*str1=*str2;
str1++;
str2++;
}
*str1='\0';
printf("Concatenated String:\n");
puts(conc);
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: