write a program to murgh two arrays in a single array.

27 Dec 2022 Balmiki Mandal 0 C Programming

C Program to Merge Two Strings into a Single String

The statement "C program to merge two strings into a single string" means creating a program in the C programming language that takes two separate strings as input and combines or concatenates them into a single string.

C program to merge two strings into a single string:

C Programming
#include<stdio.h>
#include<string.h>

int main() {
  char str1[100], str2[100], mergedStr[200];

  printf("Enter the first string: ");
  gets(str1);

  printf("Enter the second string: ");
  gets(str2);

  // Merge the two strings into the mergedStr variable
  strcat(mergedStr, str1);
  strcat(mergedStr, str2);

  // Print the merged string
  printf("The merged string is: %s\n", mergedStr);

  return 0;
}

This program works by first prompting the user to enter two strings. It then uses the strcat() function to merge the two strings into the mergedStr variable. Finally, it prints the merged string to the console.

output

Enter the first string: Hello
Enter the second string: World
The merged string is: HelloWorld

Top Resources

Write a program to merge two strings alternatively in c

Write a c program to merge two arrays in single array 

write a program to merge two string in a single single string.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.