1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do I edit my code so I can use size_t MyStrlen(const char *s1); instead of this?

Discussion in 'C' started by potato4610, Aug 28, 2010.

  1. potato4610

    potato4610 New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include 
    
    int MyStrlen(const char *si);
    
    int main() {
        char str[] = "a";
        char str1[] = "HELLO";
        char str2[] = "";
        
        printf("Length: %d \n", MyStrlen(str));
        printf("Length: %d \n", MyStrlen(str1));
        printf("Length: %d \n", MyStrlen(str2));
        return 0;
    }
    
    int MyStrlen(const char *si) {
        int input;  
        
        for(input = 0; *si; si++)
            input++;   
        
        return input;
    }
     

Share This Page