C program to concatenate two strings using while loop.












C program to concatenate two strings using while loop.




C program to concatenate two strings using while loop.



#include <stdio.h> #define MAX 100 int main() { char text1[MAX], text2[MAX]; int i, j; printf("\n Enter first string: "); gets(text1); printf("\n Enter second string: "); gets(text2); i=0; while(text1[i] != '\0') { i++; } j = 0; while(text2[j] != '\0') { text1[i] = text2[j]; i++; j++; } text1[i] = '\0'; printf("\n Concatenated strings = %s", text1); return 0; }


Output:
Enter first string: computer Enter second string: languages Concatenated strings = computer languages






Exercise: 1
Write a C program to concatenate two strings.