LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2004, 08:37 PM   #1
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Rep: Reputation: 15
Question delete content form a file(Never Mind)


I figured it out but thanks for trying to help!!!


I am creating a "Database" using an array to store the information, and have created most of the menu options, except search & delete!!! And I can not seam to figure it out.
Code:
#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

struct Score //notice its not plural

{                   // making record fields

    char student[50];
    char studentscore[50];
    int how_many;

};

//does this work???
void add_Score(int&, Score []); 
void list_Score(int, Score[]); 

int main()

{
    int num_students;

    Score Scores[50];//notices its plural
    char choice; // switch satement for asking questions
    fstream scoresdb; // data file

   scoresdb.open("scoresdb.dat");

   if (!scoresdb)

   {

	   cout << "Cannot open input file.\n";
	   return 1;

   }

    scoresdb >> num_students;   //reading the file

    for(int i=0; i < num_students; i++)

    {

	    scoresdb.getline(Scores[i].student, 50);
	    scoresdb.getline(Scores[i].studentscore, 50); 
            scoresdb >> Scores[i].student;
            scoresdb >> Scores[i].studentscore;
            scoresdb >> Scores[i].how_many;
    }

    do
    {
	cout << "What is your choice?" << endl;
	cin >> choice;
	choice = toupper(choice);

	switch (choice) 				      	

	  {                                                       

/*add*/		case 'A':  add_Score(num_students, Scores);

			cout << "\nnum_students in main after Add: "; //not sure if needed
			cout << num_students << endl;                 //not sure if needed
			break;

/*list*/	case 'L':  list_Score(num_students, Scores);
			break;

/*delete*/	case 'D': index = 0; //Is it 'index' or what? is this even right?
			while (index < lenght && item != data[index])
				Score++;

			if (index < length)
			{
				data[index] = data [lenghth-1];
				lenght--;
			}
			break;

/*search*/	case 'S': 

	     case 'Q':
                      break;

	     default:   cout << "Error in choice.  Please try again."  << endl;
      }

   }while (choice != 'Q');

   dbfile.close();

   return 0;

} // end of main function
Thanks in advance for the help

Last edited by bru; 04-28-2004 at 09:04 PM.
 
Old 04-30-2004, 07:41 AM   #2
ssba
Member
 
Registered: Mar 2004
Distribution: Slackware 9.1
Posts: 44

Rep: Reputation: 15
I do not know C file handling, so forgive me if I make a mistake.. but I see quite a few in your 'Delete' block I think you should take a look at:

Code:
while (index < lenght && item != data[index])
	Score++;
You misspelt 'length' here. I'm assuming thats what you want? I don't see any place where you have defined 'length' anyways. On another note: This looks like an infinite loop to me. 'index' is never modified.

Code:
if (index < length)
	{
Once again, I don't think 'length' has been defined yet.

Code:
data[index] = data [lenghth-1];
Yet another misspelling of 'length'.

Code:
lenght--;
And another.

I don't know if the above is all 100% correct, but I do believe that your misspellings of 'length' are some of your problem. =P
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Udev] Can I delete the content of /dev? lokee Linux - Software 6 02-04-2005 08:30 PM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM
Editior automatically delete content between lines dnla Linux - Newbie 2 10-21-2003 04:57 PM
How does one delete directories with content as the SU? Ferrell Ramey Linux - General 2 08-22-2002 07:16 PM
How to delete a dir and all it's content? ReSync Linux - Newbie 2 06-29-2002 06:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration