Advertisement
Vasilena

PracticeDayFiveExercise4

Jul 9th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void concatenate(char *str1, char *str2)
  5. {
  6.     int i = strlen(str1);
  7.     int j = 0;
  8.     while (str2[j] != '\0')
  9.     {
  10.         str1[i] = str2[j];
  11.         i++;
  12.         j++;
  13.     }
  14.     str1[i] = '\0';
  15. }
  16.  
  17. int main()
  18. {
  19.   char string1[20];
  20.   char string2[20];
  21.   printf("Enter the first string: ");
  22.   gets(string1);
  23.   printf("Enter the second string: ");
  24.   gets(string2);
  25.  
  26.   concatenate(string1, string2);
  27.  
  28.   printf("Concatenated string : ");
  29.   puts(string1);
  30.  
  31.   return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement