Concatenate two strings in C


In real world application we might be handling too many strings. In some cases, we might come across concatenation( gluing two strings ). This tutorial will help you understand the technique without using the strcat() built-in function.


Step #1. Read two string sizes in order to dynamically create the string on the fly.

Step #2. Use mallocĀ function to reserve the necessary memory for the strings

Step #3. The resulting string will have one byte more size than that of the sum of the length of these two strings.

Step #4. Read the strings

Step #5. Now store these strings character by character to the new string.

Step #6. Finally, display the string.

[Note: This algorithm can be improved in so many ways. I highly recommend to comment if found so. ]

Count Vowels, consonants or numbers in a given string.


Would You Mind Sharing?


1 Trackback / Pingback

  1. Puppeting with Strings – Never Stop Learning

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.