Comments are welcomeCode:#include <stdio.h> #include <string.h> /* The std's strlen algorithm: From: Programming with lcc-win32 by Jacob Navia and Q Software Solutions GmbH int strlen(char *str) { char *p = str; while(*p != 0) p++; return p - str; } It will crash in both.. char *test; printf("%d", strlen(test)); ..and.. char *test = NULL; printf("%d", strlen(test)); */ //This is my modified std's strlen: int strlen_mod(char *str) { //Avoiding crashes by initializing string to NULL if(str == NULL) //a very simple fix return 0; char *p = str; while(*p != 0) p++; return p - str; } //They said passing by reference gives better performance: int strlen_byref(char **str) { if(*str == NULL) return 0; char *p = *str; while(*p != 0) p++; return p - *str; } //But, let's try something simple :) : int strlen_simple(char **str) { if(*str == NULL) return 0; int len = 0; while((*str)[len] != 0) len++; return len; } int main() { char *str = "abcde"; printf("%s\n\n", str); printf("strlen : %d\n", strlen(str)); printf("strlen_mod : %d\n", strlen_mod(str)); printf("strlen_byref : %d\n", strlen_byref(&str)); printf("strlen_simple: %d\n", strlen_simple(&str)); return 0; }