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);
}
Post A Comment:
0 comments: