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!
Here are different methods to write down code for strlen:
Without Using Pointers:
int mystrlen(char s[]) {
return i;
}
With Pointers:
int strlength(char const *s) {
}
Without Counter:
int my_strlen(char const *s) {
}
Using Recursion :
int mystrlen(char const *s) {
}