Thread: Pointer Problems

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It looks like you have a logic error involving your found variable: you probably want to set it to 0 before the inner loop, then set it to 1 if s1[ i ] == s2[ j ].

    The break will break from the inner loop, not the outer loop, so there is no problem there.

    By the way, we would normally save the result of each strlen call into a variable since those values do not change here. In fact, you can make your squeeze function more const correct by making s1 and s2 be pointers to const char.

    EDIT:
    Oh wait, you do reset found to 0 at the end of the outer for loop body, so that is fine. (But I would still prefer setting it to 0 at the start of the loop.)
    Last edited by laserlight; 07-04-2012 at 10:27 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer Problems
    By TieFighter in forum C Programming
    Replies: 6
    Last Post: 02-18-2010, 05:36 PM
  2. More pointer problems :(
    By mike_g in forum C Programming
    Replies: 9
    Last Post: 07-21-2008, 07:28 AM
  3. pointer problems
    By vidioholic in forum C Programming
    Replies: 44
    Last Post: 10-12-2007, 07:22 PM
  4. Pointer problems :(
    By ryptide in forum C Programming
    Replies: 7
    Last Post: 06-16-2004, 03:37 AM
  5. pointer problems
    By tetraflare in forum C++ Programming
    Replies: 2
    Last Post: 12-06-2002, 09:01 PM