C PROGRAM TO CONCATENATE TWO GIVEN STRINGS
/*** C PROGRAM TO CONCATENATE TWO GIVEN STRINGS ***/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include<stdio.h> #include<conio.h> #define MAX 100 main() { int i,j,k; char str1[MAX],str2[MAX],strnew[2*MAX]; clrscr(); printf("\n****PROGRAM TO CONCATENATE STRINGS****\n"); printf("\nEnter the String1:"); scanf("%s",&str1); //gets(str1); //for allowing spaces in a string u can use gets() instead of scanf() printf("\nEnter the String2:"); scanf("%s",&str2); //gets(str2);//for allowing spaces in a string u can use gets() instead of scanf() printf("\n The concatinated string is:\n"); for(i=0;str1[i]!='\0';i++) { strnew[i]=str1[i]; //stroing string 1 in another string k=i; } for(j=0;str2[j]!='\0';j++) { strnew[++k]=str2[j]; //concatinating string 2 to string 1 } strnew[++k]='\0'; // ending the concated string printf("\n>> %s <<",strnew); getch(); } |
Output: