sliding window

This is a discussion on sliding window within the C Programming forums, part of the General Programming Boards category; Hi, Could anyone suggest a means to implement a sliding window over a string to compare it with another string, ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    141

    sliding window

    Hi,

    Could anyone suggest a means to implement a sliding window over a string to compare it with another string, characterwise?
    I've imagined 2 pointers, the distance between them being the window length. Now, there will be a 3rd pointer which will move from the first pointer to the last comparing each charater from the pair of string.Once it reaches the 2nd pointer, the 1stand2nd pointer gets +1 and the 3rd pointer starts again. This process continues until the 2nd pointer reaches the last character of the shorter string.
    Is the logic alright? But even if the logic is right, being a newbie to pointer I'm not getting any clue how to implement this in C. My questions are:
    1. what will be these pointers? (int???) I only know these will be pointers to characters of each string but have no clue how to denote them
    2. how can i increment and compare the 3rd pointer whether it reaches the 2nd one?
    3. is pointer at all necessary for implementing my idea?

    I'll be obliged if someone can point me to a proper direction.

    Thanks,
    Angshu

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Why not use strncmp and set the size for the window length? Then you can iterate along the string to the end with an increasing pointer.

    But isn't this really just re-implementing strstr? strstr will search for a smaller string within a larger string.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    141
    Thanks cwr. But could you please point me to an example!I'm not getting it.What is the pointer in this case that I'll increment?
    And how to declare the string?

    Thanks,
    Angshu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21