Solved

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

Posted on 2007-12-01
6
206 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
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now