C Online Compiler
Example: C Program to Concatenate two Strings without using Strcat
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Concatenate two Strings without using Strcat #include <stdio.h> // It's the main function of the program int main() { char string_1[500] = "hello this is "; char string_2[500] = "my first program"; int lenth_1; // Step-1 Get the length of the first string while (string_1[lenth_1] != '\0') { lenth_1++; } // Step-2 Concatenate string_2 to string_1 for (int i = 0; string_2[i] != '\0'; i++, lenth_1++) { string_1[lenth_1] = string_2[i]; } // Step-3 Terminate the first string string_1 string_1[lenth_1] = '\0'; // Step-3 Final output of the program printf("Concatenation result: "); puts(string_1); return 0; }
Output
Clear
ADVERTISEMENTS