for/if/else dilemma - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: for/if/else dilemma

  1. #16
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: for/if/else dilemma

    See my earlier post. I took another look and I understand the problem better. I haven't troubleshot that but I will leave that up to you to determine how the user input ends up in the array 4 times. There is nothing wrong with the contents of the for loop.

    I'd suggest that if you really want to improve things, use std::string with getline. The user input could easily overrun the destination arrays causing undefined behavior.

  2. #17
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: for/if/else dilemma

    Oh I get it. You are appending to the files. Therefore if you run the program multiple times the data keeps being added to the file. So if you are running the program over and over you could end up seeing duplicate output due to the same information being added over and over. Again it has nothing to do with the if..else..if statements in the search function.

  3. #18
    Join Date
    Jan 2010
    Posts
    8

    Re: for/if/else dilemma

    so.. i found out what the real problem is. i thought that after doing first or second if the search jumps to the third if but actualy after doing first or second if it runs the for again, thus doing the third if and i get both solutions. if i added 2-3 more ifs that matched the search_word it would, after every if matb]ched, jump again to the for until there aren't any other ifs matching the search_word.

    any ideea why it's doing this?

    thanks for your solutions so far

  4. #19
    Join Date
    Apr 1999
    Posts
    27,427

    Re: for/if/else dilemma

    Quote Originally Posted by darkseid View Post
    any ideea why it's doing this?
    That's how for() loops work.
    Code:
    for(i=0; i<n; i++)
    This will loop n times, unless a break statement stops the loop.

    Regards,

    Paul McKenzie

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center