Implement Custom strlen Function

Code

#include <stdio.h>
#include <string.h>

int strlen_custom(const char *str){
    int count = 0; 
    while(str[count] != '\0'){
        count++;
    }
    return count;
}

int main(){
    char str[101]; 
    fgets(str, sizeof(str), stdin);
    str[strcspn(str,"\n")] = '\0';

    printf("%d\n",strlen_custom(str));

    return 0;
}  

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

Embedded

Expected Output

8