Re: calculating length of an substring



On Feb 29, 6:43 pm, "brasil...@xxxxxxxxx" <brasil...@xxxxxxxxx> wrote:

I'm trying to calculating a substring length directly from pointer
address, like this:

char *e = NULL, *s = NULL;
int len = 0;

s = strchr (url,'.');
e = strrchr (url,'?');
len = (int) s - e;

You need to check that both s and e are notnull, and you probably
mean:

len = (int) (e - s);

Your version is equivalent to:
len = ((int)s) - e;

and the compiler is complaining about subtracting a pointer
from an int.
.



Relevant Pages