Re: calculating length of an substring



"brasilino@xxxxxxxxx" <brasilino@xxxxxxxxx> writes:

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;

try using braces:

len = (int) (s - e);

casting binds tighter than subtraction.

--
burton



.



Relevant Pages

  • Re: parsing a string
    ... YYYYMMDD from the following string. ... strrchr() doesn't seem to be the answer here. ... I suppose I'm so used to thinking of strchr ... strchr strchr to find the third foo in the bar, and so used to thinking of ...
    (comp.lang.c)
  • Re: reformatting strings and memory issue
    ... As for strchr() vs strrchr() I guess its academic since each character ... input string anyway. ... I'll look at the extra characters issue. ...
    (comp.lang.c)
  • Re: About Strings in C lang
    ... > I am writing a C language program in Unix. ... strrchr [strchr] - locate character in string ...
    (comp.unix.questions)