You are using a version without Ads of this website. Please, consider donating:

### N idea

Pages: 123
What? I'm sorry you got to give me more words to go with that. Are you declaring a vector? I haven't learned those yet actually. If you are
Try the code above first. (only pointers) In fact now I'm busy... :)
The code you gave me or the one above it ? The one that threw the crazy error?
Now then you post all your code here, I will recompile the project and do the algorithm for you... (Actually my example is from my mind...) :)
You should memorize carefully the algorithm and how this algorithm works.
Agree?
Last edited on
`tele[i] = tele[i-1] ; ` -> element to the right = element to the left.

My code:
`a[move_me-1] = a[move_me] ;` -> element to the left = element to the right.

Your code sets everything that occurs after the element to be deleted to be equal to the element to be deleted. You don't need to return the new size. It's modified within the function body.

As for your crash, hard to say.
Yes I still get that error even with your code. It compiles just throws some crazy error after unhandled exception. You will have to give me words with the algorithm because sometimes looking at code isn't enough for me.
Thanks

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165`` ``````#include #include #include #include using namespace std; const int SIZE = 5; //structure struct infoType { string fname; string lname; string streetAdd; string cityStateZ; string phone; }; // Function to get info from file. void readData(ifstream &fin, infoType tele[], int& size) { int i = 0; while(!fin.eof()) { fin >> tele[i].fname; fin >> tele[i].lname; fin.get(); getline(fin,tele[i].streetAdd, '\n'); getline(fin,tele[i].cityStateZ, '\n'); getline(fin,tele[i].phone, '\n'); i++; } size = i; } //Function to display Menu void displayMenu() { cout << "Phone Directory Program " << endl; cout << endl; cout << "Options" << endl; cout << "[A]dd and entry to the phone directory. " << endl; cout << "[D]elete an entry from the phone directory. " << endl; cout << "[U]pdate an entry from the phone directory. " << endl; cout << "[L]ist the entire phone directory. " << endl; cout << "[E]xit the menu" << endl; } //Option A function int optionA(ifstream &fin, infoType tele[], int& size) { // Still need formatting cout << "----You have selected option A---- " << endl; cout << endl; cout << "Please enter the first name. " << endl; for(int i = 0; i < 1; i++) { cin >> tele[i].fname; } cout << "Please enter the last name. " << endl; for(int i= 0; i < 1; i++) { cin >> tele[i].lname; } cout << "Please enter the street address. " << endl; cin.get(); for(int i = 0; i < 1; i++) { getline(cin,tele[i].streetAdd); } cout << "Please enter the city, state and zip code." << endl; for(int i = 0; i < 1; i++) { getline(cin,tele[i].cityStateZ); } cout << "Please enter the phone number.(Example, 555-555-5555)" << endl; for(int i = 0; i < 1; i++) { cin >>tele[i].phone; } size++; return size; } //Remove function int remove( infoType tele[], int& size, int position_of_item_to_remove ) { for( int i = position_of_item_to_remove + 1 ; i < size ; ++i ) tele[i] = tele[i-1] ; return --size; } //Option D function void optionD( ifstream &fin, infoType tele[], int& size) { int index = 0; string dPhone; bool found = false; int nCount = 0; cout << "You have selected option D " << endl; cout << "Please enter the phone number of the record to be deleted." << endl; cout << "(Example, 555-555-5555)" << endl; cin >> dPhone; while( index < size && !found ) { if(tele[index].phone.compare(dPhone)== 0) { cout << "The entry to be deleted is " << endl; cout << tele[index].lname << endl; cout << tele[index].fname << endl; cout << tele[index].streetAdd << endl; cout << tele[index].cityStateZ << endl; cout << tele[index].phone << endl; //Remove infoType *temp[100]; //Not vectors now, quick for(int i = index; i < size;i++) {temp[nCount] = &tele[i];nCount++;} for(int i = index; i < size;i++) {nCount--;tele[i] = (*temp[nCount]);} size--; found = true; } else index++; } } int main() { ifstream fin("input.txt"); int newSize = 10; infoType tele[SIZE]; readData(fin, tele, newSize ); newSize = optionA(fin, tele,newSize); optionD(fin,tele,newSize); //displayMenu(); system("pause"); return 0; }``````
Jackson is this a vector declaration?
` infoType *temp[100];`
The program can't run. But, this is the algorithm :
 int nCount = 0; infoType temp[SIZE]; for(int i = index; i < size;i++) {temp[nCount] = tele[i];nCount++;} for(int i = index; i < size;i++){ nCount--;tele[i] = temp[nCount];} size--;
Last edited on
Why can;t it?
I keep getting that error I need to figure that out .
What's the error? I don't understand what you are saying.
Do not say again :
 Unhandled exception at 0x5c1dcafa (msvcr100d.dll) in newnew.exe: 0xC0000005: Access violation writing location 0xcccccccc.

That's meant there is an another crash at somewhere in your code.
Thats what it is dude.
well this
Unhandled exception at 0x5c1abef0 (msvcr100d.dll) in newnew.exe: 0xC0000005: Access violation reading location 0xcccccccc.

 Thats what it is dude.

No.

You used "FILE" functions. (Perhaps)
Or recompile this project in "input mode"?
Last edited on
I don't know how to describe it. The program runs. Takes the info. Then it just goes nuts when it gets to The entry to be deleted. And it goes to that side screen with all the code and displays the message you told me not to do again.
Once again, input mode?
Or follow the file input syntax?
When it goes to the side tab it says' isofwd

then the curser hangs out around this section of code

 ``12345`` ``````static _Elem *__CLRCALL_OR_CDECL copy(_Elem *_First1, const _Elem *_First2, size_t _Count) { // copy [_First1, _First1 + _Count) to [_First2, ...) return ((_Elem *)_CSTD memcpy(_First1, _First2, _Count)); }``````

I have no clue what the issue is in my program.
I apologize I don't know what input mode and input syntax are I'm really sorry.

I'm going to guess and say input file syntax are you asking if my program reads things from a file? I'm sorry. I don't understand.
So lots of changes. Debug?
Last edited on
I don't know what you mean.
Debug is not going good same thing This is my entire Code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176`` ``````include #include #include #include using namespace std; const int SIZE = 5; //structure struct infoType { string fname; string lname; string streetAdd; string cityStateZ; string phone; }; // Function to get info from file. void readData(ifstream &fin, infoType tele[], int& size) { int i = 0; while(!fin.eof()) { fin >> tele[i].fname; fin >> tele[i].lname; fin.get(); getline(fin,tele[i].streetAdd, '\n'); getline(fin,tele[i].cityStateZ, '\n'); getline(fin,tele[i].phone, '\n'); i++; } size = i; } //Function to display Menu void displayMenu() { cout << "Phone Directory Program " << endl; cout << endl; cout << "Options" << endl; cout << "[A]dd and entry to the phone directory. " << endl; cout << "[D]elete an entry from the phone directory. " << endl; cout << "[U]pdate an entry from the phone directory. " << endl; cout << "[L]ist the entire phone directory. " << endl; cout << "[E]xit the menu" << endl; } //Option A function int optionA(ifstream &fin, infoType tele[], int& size) { // Still need formatting cout << "----You have selected option A---- " << endl; cout << endl; cout << "Please enter the first name. " << endl; for(int i = 0; i < 1; i++) { cin >> tele[i].fname; } cout << "Please enter the last name. " << endl; for(int i= 0; i < 1; i++) { cin >> tele[i].lname; } cout << "Please enter the street address. " << endl; cin.get(); for(int i = 0; i < 1; i++) { getline(cin,tele[i].streetAdd); } cout << "Please enter the city, state and zip code." << endl; for(int i = 0; i < 1; i++) { getline(cin,tele[i].cityStateZ); } cout << "Please enter the phone number.(Example, 555-555-5555)" << endl; for(int i = 0; i < 1; i++) { cin >>tele[i].phone; } size++; return size; } //Remove function int remove( infoType tele[], int& size, int position_of_item_to_remove ) { for( int i = position_of_item_to_remove + 1 ; i < size ; ++i ) tele[i-1] = tele[i] ; return --size; } //Option D function void optionD( ifstream &fin, infoType tele[], int& size) { int nCount = 0; int index = 0; string dPhone; bool found = false; infoType temp[SIZE]; cout << "You have selected option D " << endl; cout << "Please enter the phone number of the record to be deleted." << endl; cout << "(Example, 555-555-5555)" << endl; cin >> dPhone; while( index < size && !found ) { if(tele[index].phone.compare(dPhone)== 0) { cout << "The entry to be deleted is " << endl; cout << tele[index].lname << endl; cout << tele[index].fname << endl; cout << tele[index].streetAdd << endl; cout << tele[index].cityStateZ << endl; cout << tele[index].phone << endl; //Remove for(int i = index; i < size; i++ ) { temp[nCount] = tele[i]; nCount++; } for(int i = index; i < size; i++ ) { tele[i] = temp[nCount]; nCount--; } size--; found = true; } else index++; } } int main() { ifstream fin("input.txt"); int newSize = 10; infoType tele[SIZE]; readData(fin, tele, newSize ); newSize = optionA(fin, tele,newSize); optionD(fin,tele,newSize); //displayMenu(); system("pause"); return 0; }``````

I have no clue what the issue it.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990`` ``````int remove( infoType tele[], int& size, int position_of_item_to_remove ) { for( int i = position_of_item_to_remove + 1 ; i < size ; ++i ) tele[i-1] = tele[i] ; return --size; } //Option D function void optionD( ifstream &fin, infoType tele[], int& size) { int nCount = 0; int index = 0; string dPhone; bool found = false; infoType temp[SIZE]; cout << "You have selected option D " << endl; cout << "Please enter the phone number of the record to be deleted." << endl; cout << "(Example, 555-555-5555)" << endl; cin >> dPhone; while( index < size && !found ) { if(tele[index].phone.compare(dPhone)== 0) { cout << "The entry to be deleted is " << endl; cout << tele[index].lname << endl; cout << tele[index].fname << endl; cout << tele[index].streetAdd << endl; cout << tele[index].cityStateZ << endl; cout << tele[index].phone << endl; found = true ; } else index++ ; } if ( found ) remove(tele, size, index) ; else cout << "Number was not found!\n" ; } void print( const infoType directory[], unsigned size ) { cout << size << " numbers in directory\n" ; for ( unsigned i=0; i