removing structures via pointers

I'm supposed to write a remove() function to take out some data, however, it seems none of the info is being saved anyways, as when I try to print out all of the info in my structure, I get nothing (dispAll()).

it also seems that the remove() function isn't able to find anything, even if I know it should be there. The only time it seems to recognize there is something in Name/phoneNo is in dispOne(). can anyone tell me what I'm doing wrong or what I need to change to get this to work? Any help is appreciated.

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
#include <iostream>
#include <string>
#include <cstdio>
#include <conio.h>
#include <iomanip>
#include <cstdlib>
using namespace std;

int x = 0;
struct TeleType
{
       string Name[100];
       string phoneNo[100];
};
void populate(TeleType *);
void dispOne(TeleType *);
void remove(TeleType *);
void dispAll(TeleType *);

int main()
{
    char key = 'a';
    TeleType *recPoint;
    
    do
    {
          if (key == 'n')
          {
                  key = cin.get();
                  recPoint = new TeleType;
                  populate(recPoint);
                  dispOne(recPoint);
                  x++;
          }
          if (key == 'd')
          {
                  key = cin.get();
                  recPoint = new TeleType;
                  remove(recPoint);
                  dispAll(recPoint);
          }
          cout << "\nDo you want to create or delete a new record? (n for new, d for delete, e to exit): ";
          key = cin.get();
    }
    while (key != 'e');
    getch();
    return 0;
}

void populate(TeleType *record)
{
     cout << "Enter a name: ";
     getline(cin, record->Name[x]);
     cout << "Enter the phone number: ";
     getline(cin, record->phoneNo[x]);
     
     return;
}

void dispOne(TeleType *contents)
{
     cout << "\nThe contents of the record just created are:"
          << "\nName: " << contents->Name[x]
          << "\nPhone Number: " << contents->phoneNo[x] << endl;
     return ;
}

void remove(TeleType *removing)
{
     int i, j;
     string str;
     cout << "Enter the name you wish to remove: ";
     cin >> str;
     for (i = 0; i < x; i++)
     {
         if (str == removing->Name[x])
         {
                 for (j = i; j < x - 1; j++)
                 {
                     removing->Name[j] = removing->Name[j+1];
                     removing->phoneNo[j] = removing->phoneNo[j+1];
                 }
         x--;
         return;
         }
     }
     cout << "The name " << str << " was not found, sorry!";
     return;
}

void dispAll(TeleType *contents)
{
     int z;
     for (z = 0; z < x; z++)
     {
         cout << "\nThe contents of the record just created are:"
              << "\nName: " << contents->Name[z]
              << "\nPhone Number: " << contents->phoneNo[z] << endl;
     }
     return;
}
TeleType has your collection of records. Well, it's more a collection of fields, but that's ok for beginners I guess. And you maintain a record count with x.

You should create just one instance of TeleType, probably alongside the declaration of x.

What you're doing wrong is:
Each time you create a new record, you create a new empty TeleType instance. You add your record to it and forget about it, so the record is lost.
Each time you attempt to delete a record, you create a new empty TeleType instance, and look for your record, but it isn't there.

Got it?
So it turns out I made a stupid error (line 76). Sorry for wasting everyone's time. kbw, thanks for your response.
Topic archived. No new replies allowed.