String length between pointers

c, char, pointers

Solution

Just

length = end - start;

without ampersands and casts. C pointer arithmetics allows this operation.

Problem

I ran into a little problem and need some help: If I have an allocated buffer of chars and I have a start and end points that are somewhere inside this buffer and I want the length between these two point, how can I find it? i.e ``` char * buf; //malloc of 100 chars char * start; // some point in buff char * end; // some point after start in buf int length = &end-&start? or &start-&end? //How to grab the length between these two points. ``` Thanks

Original source