Deleting item from array

Hi everyone, im programing an agenda in c++ but im having a little trouble erasing an entry. Sorry the code is long, i was too lazy to use call functions... anyways bear with me.
i tried setting the value to NULL on the entry i want to erase but that doesnt work, someone told me to change it to "0", but that doesnt work either. any advice please?.

the code was too long so i had to upload the cpp file mediafire

http://www.mediafire.com/?x6z64wsa39qpw2u

so sorry
Last edited on
Why not cut it down to the new statement and the delete statement with anything relevant in between? That would be easy for us to read and help you with.
alright here you gooo
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
                           found=false;
                           cout<<"Which entry do you wish to eliminate?\n";
                           cin>>number;
                           
                           //start sort
                           for(int b=1;b<a;b++)
                           {
                               tempcl=cla[b];
                               tempnu=num[b];
                               tempno=nom[b];
                               
                               n=b-1;
     
                               while(cla[n]>tempcl && n>=0)
                               {                                                  
                                   cla[n+1]=cla[n];
                                   nom[n+1]=nom[n];
                                   num[n+1]=num[n];
                                   n--;
                               }
                               cla[n+1]=tempcl;
                               nom[n+1]=tempno;
                               num[n+1]=tempnu;
                               
                           }//end sort
                                              
                           mid=cla;
                           
                           int z=0;
                           int x=2;
                           int y=4;
                           while(z<=y)
                           {
                                if(number<mid[x])
                                {
                                     y=x-1;
                                     x=(z+y)/2;    
                                }
                                else
                                {
                                }
                                
                                if(number>mid[x])
                                {
                                     z=x+1;
                                     x=(z+y)/2;
                                }
                                else
                                {
                                }
                                
                                if(number==mid[x])
                                {
                                     found=true;
                                     z=5;
                                     
                                }
                                else
                                {
                                }
                                 
                            }
                           
                           if(found==true)
                           {
                               cout<<"This entry will be eliminated!\n";
                               cout<<"Control\tName\tPhone\n";
                               cout<<cla[x]<<"\t"<<nom[x]<<"\t"<<num[x]<<endl;
                               
                               system("pause");
                               
                               cla[x]=0;
                               nom[x]="";
                               num[x]=0;
                               a--;
                               
                               cout<<"The entry has been erased!\n";
                               
                           }
                           else
                           {
                               cout<<"That number was not found!\n"<<endl;
                           }
                           
                           
There's no new or delete statement in that code.

Without knowing how cla[x] nom[x] and num[x] were allocated, it's impossible to say what the correct thing to do on lines 72-74 is.

Generally when you 'erase' something from an array you do so by shifting the elements past the one you're erasing to the left, and updating any variable indicating the number of stored elements in the array.

Use pastebin or ideone or something similar in lieu of mediafire if you must. Better is to reduce the code to something small that still exhibits the same problem and post with that.
Topic archived. No new replies allowed.