Solved

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

Posted on 2007-12-01
6
219 Views
Last Modified: 2010-04-21
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;
}
0
Comment
Question by:jschmuff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:jschmuff
ID: 20389322
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.
0
 

Author Comment

by:jschmuff
ID: 20389340
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
0
 
LVL 86

Accepted Solution

by:
jkr earned 350 total points
ID: 20389377
You should rather output only the words except the one to remove, e.g.

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)
            {
                  Datfile << Words[Loop] << endl;
            }
      }
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 20389388
looks like its taking the word count!
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 20389390
Sorry Letter count in a word
0
 

Author Closing Comment

by:jschmuff
ID: 31412136
It gets so confusing when there is ton and tons of code... lol thx again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question