Advertisement
yudakov1814

Untitled

Apr 10th, 2020
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int strlen(const char str[]) {
  4.     int length = 0;
  5.     while (*str++) {
  6.         ++length;
  7.     }
  8.     return length;
  9. }
  10.  
  11. void strcpy(char target[], const char source[]) {
  12.     while (*target++ = *source++);
  13. }
  14.  
  15. int strcmp(const char lhs[], const char rhs[]) {
  16.     while (*lhs || *rhs) {
  17.         if (*lhs++ != *rhs++) {
  18.             return *(lhs - 1) - *(rhs - 1);
  19.         }
  20.     }
  21.     return 0;
  22. }
  23.  
  24. int main() {
  25.     const int maxLen = 100;
  26.     char str1[maxLen];
  27.     char str2[maxLen];
  28.     gets_s(str1);
  29.     gets_s(str2);
  30.     printf("strlen(str1) = %d\n", strlen(str1));
  31.     printf("strlen(str2) = %d\n", strlen(str2));
  32.     printf("strcmp(str1, str2) = %d\n", strcmp(str1, str2));
  33.     strcpy(str2, str1);
  34.     printf("str1 = %s\n", str1);
  35.     printf("str2 = %s\n", str2);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement