kucheasysa

concatenate string

Jun 6th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void concatenateStrings(char str1[], char str2[]) {
  4. int i, j;
  5. for (i = 0; str1[i] != '\0'; i++);
  6. for (j = 0; str2[j] != '\0'; i++, j++) {
  7. str1[i] = str2[j];
  8. }
  9. str1[i] = '\0';
  10. }
  11.  
  12. int main() {
  13. char str1[100], str2[50];
  14.  
  15. printf("Enter the first string: ");
  16. fgets(str1, sizeof(str1), stdin);
  17.  
  18. printf("Enter the second string: ");
  19. fgets(str2, sizeof(str2), stdin);
  20.  
  21. concatenateStrings(str1, str2);
  22.  
  23. printf("Concatenated string: %s\n", str1);
  24.  
  25. return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment