Skip to main content

Posts

Showing posts with the label concatenate two strings in c

Sample C Program To Concatenate Two Strings.

#include <stdio.h> #include <conio.h> #include <string.h> int main() { char a[100], b[100]; printf(" Enter the first string " ); gets(a); printf(" Enter the second string " ); gets(b); strcat( a, b ); printf(" String obtained on concatenation is %s\n ", a ); getch(); return 0; } OUTPUT: Enter the first string Team Enter the second string mates String obtained on concatenation is Teammates C Program To Concatenate Two Strings Without Using strcat() Function. #include <stdio.h> int main() {     char str1[50], str2[50], i, j;     printf("\nEnter first string: ");     scanf("%s",str1);     printf("\nEnter second string: ");     scanf("%s",str2);     for(i=0; str1[i]!='\0'; ++i);     for(j=0; str2[j]!='\0'; ++j, ++i)     {         str1[i]=str2[j];     }     str1[i]='\0';     printf("\nOutp...