Please post the contents of From Form.txt and StoreDatabase.txt. If they are too big then post some representative sample of their contents - enough to use in test run. If this is an assignment then please post the full assignment text. We ask this because beginners frequently miss some detail that affects how the program should be written.
Looking at your original code:
- why do you open secondfile twice (lines 30 and 47)?
- You read C at line 41 and again at line 48. Is that intentional?
- The loop at line 52 will never run. Since your looping while the file
is at the end instead while it is
not at the end. Using end-of-file is actually a bad way to do this since eof won't be true until the program tries to read
past the end. Replace lines 52-54 with:
while (getline(infile2,line)) {
- You open and close confirmed each time you write to it. I'm not certain, but I think each time you open it, it clears the contents and writes at the beginning, so every write blows away whatever was written before. You could fix this by opening it in append mode, but it would be easier and clearer if you just opened it once.
It appears that you're trying to separate the input file contents into the "confirmed" file and the "not confirmed" file. If that's true then Andy's point about indentation should show that you need to rearrange the logic.
Line 55 is probably insufficient for what you want. You're just searching for the registration code in the entire line of text. What if the registration code shows up in the customer's name? What if you're looking for registration code ABC and there's a line with registration code ABCD? You'd think that ABCD is confirmed.
It sounds like you need functions to read and write an applicant. The loop should be (in pseudo-code)
1 2 3 4 5 6 7
|
while (read an applicatant) {
if (application.registrationCode == inputRegistration code) {
write applicatant to confirmed file
} else {
write applicant to unconfirmed file
}
}
| |