All submissions

Implement Custom strlen Function

Code

#include <stdio.h>

int custom_strlen(const char *str) {
    int len=0;
    char c;

    while(c!='\0')
    {
        c = str[len];
        len++;
    }
    return len-1;
}

int main() {
    char str[101];
    fgets(str, sizeof(str), stdin);

    // Remove newline if present
    int i = 0;
    while (str[i] != '\0') {
        if (str[i] == '\n') {
            str[i] = '\0';
            break;
        }
        i++;
    }

    printf("%d", custom_strlen(str));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

Embedded

Expected Output

8