Solved

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

Posted on 2007-12-01
6
210 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

776 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