Link to home
Start Free TrialLog in
Avatar of jschmuff
jschmuffFlag for United States of America

asked on

deleting words from a file... cant save the output

I am having issues with saving the output for my code here is my delete code.

void Game::deleteWords()
{
      myGame.loadFile();
      ofstream Datfile("words.txt");

      cout << "\tEnter a word to remove from list: ";
      cin >> Word;

      Size = strlen(Word);

      for(Loop = 0; Loop < Count; Loop++)
      {
            if(strcmp(Words[Loop],Word) == 0)
            {
                  strcpy_s(Words[Loop],MAX_WORD_SIZE,Words[--Count]);
                  strcpy_s(Words[Count], "");
                  break;
            }
      }
    for (int i = 0; i < Count - 1; i++) Datfile << Words[i] << endl;
}
Avatar of jschmuff
jschmuff
Flag of United States of America image

ASKER

before you guys answer this... I fixed a small typo it works, but there is a major problem it will delete the word I type in but will also delete every word as well.
ok I ran some more test on it.. it doesnt always delete all the words like the words in there were

programming
class
maxine
heidi
john

I choose to delete class and it removes heidi also.. what is the problem
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
looks like its taking the word count!
Sorry Letter count in a word
It gets so confusing when there is ton and tons of code... lol thx again.