搜尋此網誌

[C/C++][strlen實作]

/*
* Author: MH
* Since 2013/10/29
* Toolkit: Code::Block 12.11
*/

#include <stdio.h>

int strlen_implementaion (const char *str) {
    int countStr = 0;
    while (*(str+countStr)!='\0')
            countStr++;
    return countStr;
}

int main () {
    char *str = "abcde";
    printf("%d", strlen_implementaion(str));    // 5
    return 0;
}

沒有留言:

張貼留言