Advertisement
DrAungWinHtut

strmanip1.c

Oct 10th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. char* strcpyy(char* s2, const char* s1);
  5. int strlenn(const char* s);
  6. char* strcatt(char* s1, const char* s2);
  7.  
  8. int main() {
  9.     char str1[30] = "Hello, ";
  10.     char str2[] = "World!";
  11.     printf("count of str1 = %d\n", strlenn(str1));
  12.     strcatt(str1, str2);
  13.     printf("Concatenated string: %s\n", str1);  // Output: "Hello, World!"
  14.     return 0;
  15. }
  16.  
  17. char* strcpyy(char* s2, const char* s1)
  18. {
  19.     while (*s1)
  20.     {
  21.         *s2 = *s1;
  22.         s1++;
  23.         s2++;
  24.     }
  25.     *s2 = '\0';
  26.     return s2;
  27. }
  28.  
  29.  
  30. char* strcatt(char* s1, const char* s2)
  31. {
  32.     int first_end = strlenn(s1);
  33.     while (*s2)
  34.     {
  35.         *(s1 + first_end) = *s2;
  36.         first_end++;
  37.         s2++;
  38.     }
  39.     *(s1 + first_end) = '\0';
  40.  
  41.     return s1;
  42. }
  43.  
  44. int strlenn(const char* s)
  45. {
  46.     int count = 0;
  47.     while (*s)
  48.     {
  49.         s++;
  50.         count++;
  51.     }
  52.     return count;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement