#include <stdio.h>

// 1. String Length (Exercise 8.30)
size_t my_strlen_arr(const char *s) {
    size_t i = 0;
    while (s[i] != '\0') i++;
    return i;
}
size_t my_strlen_ptr(const char *s) {
    size_t len = 0;
    while (*s++) len++;
    return len;
}

// 2. String Copy (Exercise 8.28)
void my_strcpy_arr(char *s1, const char *s2) {
    int i = 0;
    while ((s1[i] = s2[i]) != '\0') i++;
}
void my_strcpy_ptr(char *s1, const char *s2) {
    while ((*s1++ = *s2++));
}

// 3. String Compare (Exercise 8.29)
int my_strcmp_arr(const char *s1, const char *s2) {
    int i = 0;
    while (s1[i] == s2[i] && s1[i] != '\0') i++;
    return s1[i] - s2[i];
}
int my_strcmp_ptr(const char *s1, const char *s2) {
    while (*s1 == *s2 && *s1 != '\0') {
        s1++; s2++;
    }
    return *s1 - *s2;
}

int main(void) {
    char str1[50];
    char str2[] = "Hello";
    char str3[] = "World";

    my_strcpy_ptr(str1, str2);
    printf("Copied string: %s\n", str1);
    printf("Length of string: %zu\n", my_strlen_arr(str1));
    printf("Comparison result: %d\n", my_strcmp_ptr(str2, str3));

    return 0;
}