Write a C program to concatenate two string together without using library function

In this article we will learn how write C program to concatenate two string together without using library function.

concatenate two string together without using library function

Answer:

  1. #include<stdio.h>
  2. #include<string.h>
  3. void concat(char[], char[]);
  4. int main() {
  5. char s1[50], s2[30];
  6. printf("\nEnter String 1 :");
  7. gets(s1);
  8. printf("\nEnter String 2 :");
  9. gets(s2);
  10. concat(s1, s2);
  11. printf("\nConcated string is :%s", s1);
  12. return (0);
  13. }
  14. void concat(char s1[], char s2[]) {
  15. int i, j;
  16. i = strlen(s1);
  17. for (j = 0; s2[j] != '\0'; i++, j++) {
  18. s1[i] = s2[j];
  19. }
  20. s1[i] = '\0';
  21. }

Post a Comment (0)
Previous Post Next Post