-
January 19th, 2010, 05:14 PM
#16
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.
-
January 19th, 2010, 05:19 PM
#17
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.
-
January 21st, 2010, 08:22 AM
#18
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
-
January 21st, 2010, 09:38 AM
#19
Re: for/if/else dilemma
Originally Posted by darkseid
any ideea why it's doing this?
That's how for() loops work.
This will loop n times, unless a break statement stops the loop.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|