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
Your code:
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
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.

Sorry I had too. What do I do about this? Why did you say the program coud;n't run?
Thats what it is dude.

No.
Sorry I had too. What do I do about this? Why did you say the program coud;n't run?

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

1
2
3
4
5
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
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.
Remove File functions and add debug information. :) Because : "File Not Found"
Well, it's hard what to say what your trouble using the remove function was since you didn't actually post the compilable code that you tried it with. I'm not sure what you think you're trying to do now.

This works fine for me. Note: Added some debugging aids to main. minor change in optionD. Commented out the call to OptionA in main, since what it does makes no sense - debug one thing at a time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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<size;  ++i )
        cout << "- " << left << setw(10) << directory[i].lname << setw(10) 
        << directory[i].fname << directory[i].streetAdd << '\n'
        << '\t' << setw(25) << directory[i].cityStateZ << directory[i].phone 
        << '\n' ;
}


int main()
{
    ifstream fin("input.txt");

    const unsigned teleCapacity = 10 ;
    infoType tele[teleCapacity];
    int size = 0 ;

    cout << "Before read\n" ;
    print( tele, size ) ;

    readData(fin, tele, size );

    cout << "\n\nAfter read\n" ;
    print(tele, size) ;

    //	size = optionA(fin, tele, size);

    cout << "\n\nAfter optionA\n" ;
    print(tele, size) ;

    optionD(fin,tele, size);

    cout << "\n\nAfter optionD\n" ;
    print(tele, size) ;

    //displayMenu();

    system("pause");

    return 0;

}
Last edited on
Pages: 123