4

C Program to Concatenate Two Strings

 1 year ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-concatenate-two-strings-czqgvc/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

C Program to Concatenate Two Strings

C Program to Concatenate Two Strings
Hello everyone. Welcome to the gig for geeks. My name is Erin
  • 180 Views
  • 14/07/2022

In this video, we will learn how to Concatenate Two Strings in C.

Examples:
Input String 1: GEEKSFOR
Input String 2: GEEKS
Output String: GEEKSFORGEEKS

Input String 1: HELLO
Input String 2: WORLD!!
Output: HELLO WORLD!!

Here we see different methods for string concatenation:
1. Using while loop
2. Using strcat()

Using while loop: Here we use a while loop that concatenates two strings by repeatedly copying the first string to the end of the second. The first string is terminated by a NULL character. 

Using strcat(): In C, strcat() is a predefined function used for string handling, under the string library (string.h in C). It appends the string pointed to by the source to the end of the string pointed to by the destination. It will append a copy of the source string in the destination string plus a terminating Null character. 

The initial character of the string(src) overwrites the Null-character present at the end of the string(dest).

C Program to Concatenate two strings: https://www.geeksforgeeks.org/c-program-to-concatenate-two-strings-without-using-strcat/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK