if anyone has ever wanted to try and rewrite a string function in C
, would this code work to replace the standard strlen()
function?
I have not been able to run this code because I am sitting in my car typing it on my iPhone.
int strlen(char * s) {
int i = 0, sum = 0;
char c = s[0];
while(c != '\0') {
sum++;
c = s[++i];
}
return sum;
}
You feedback is so much appreciated!