I want to rthe following error message......error: invalid conversion from ‘const char*’ to ‘size_t’</p>
return 0;
}
size_t strlen(const char *s1)
{
return s1 - 0;
}
Subtracting zero from a pointer does not change the pointer, the same way that subtracting zero from a number does not change a number.
You should subtract the original pointer, not zero, to get the length:
size_t strlen(const char *s1) {
const char *orig = s1;
while (*s1) {
s1++;
}
return s1 - orig;
}