14 July 2010

Simple implemenation for C strlen

// str_len.c.c 
#include <stdio.h>
size_t strlen(char*);

int main(void)
{
char* name = "ThisIsAStringLiteral";
printf("%u\n", strlen(name));
return 0;
}

size_t strlen(char *str){
auto unsigned long n=0;
while (*str++) n++;
return ++n; // for '\0'
}

Post a Comment