[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-12-01
6
Medium Priority
?
230 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 1400 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
Industry Leaders: 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:Deepu Abraham
ID: 20389388
looks like its taking the word count!
0
 
LVL 11

Expert Comment

by:Deepu Abraham
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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

656 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