This program counts the length of a string by subtraca warning message
-\
My stringLength function returns a size_t that is
Is my mistake in the format specifier or how I return my value?
#include <stdio.h>
#include <stdlib.h>
size_t stringLength(const char *str);
int main(void)
{
return 0;
}
size_t stringLength(const char *str)
{
const char *strCopy = str;
while (*str)
{
str++;
}
}
The issue you’re having is that
operator-()returns a signed value, rather than unsigned. Because in your routine you know that the value will always be positive, you can add a cast tosize_tand not worry about the sign being wrong.or