Thread: Searching for a particular address in a given range

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    If *low and *high point to the same memory block, (ie you char * p = malloc(100); and assign points to this same object) then the memory is in fact in order and linear...so you can already do a binary search on it because the address ARE sorted.

    Though as early pointed out if you know the address, you would just access it directly; therefore perhaps hes meaning how do I find the letter pointed to by *somep within the range low, high, which are boundaries pointing into a string?? In which case we just suggest strchr() or a for loop...

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nonpuz View Post
    If *low and *high point to the same memory block, (ie you char * p = malloc(100); and assign points to this same object) then the memory is in fact in order and linear...so you can already do a binary search on it because the address ARE sorted.

    Though as early pointed out if you know the address, you would just access it directly; therefore perhaps hes meaning how do I find the letter pointed to by *somep within the range low, high, which are boundaries pointing into a string?? In which case we just suggest strchr() or a for loop...
    But all this also begs the question of why do we need to search if we already know the address...

    Perhaps our vague friend wants to know if a given pointer is between two other pointers (i.e. in a given range) in which case a simple if() statement will suffice...

    Code:
    int InRange(char *ptr, char *start, char *end)
      { return (ptr >= start) && (ptr <= end); }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Searching for a particular address in a given range
    By xyz1987 in forum C Programming
    Replies: 6
    Last Post: 11-20-2010, 08:24 AM
  2. Replies: 1
    Last Post: 11-07-2010, 11:39 PM
  3. IP address range matching
    By Thantos in forum Tech Board
    Replies: 2
    Last Post: 07-16-2009, 04:28 PM
  4. Block address from word address
    By xddxogm3 in forum Tech Board
    Replies: 0
    Last Post: 04-25-2007, 09:02 PM
  5. Range
    By volk in forum C Programming
    Replies: 3
    Last Post: 12-19-2002, 09:43 AM