Passing pointers to functions within functions URGENT.

I have a lab due tomorrow, so thanks for a quick reply.
For some reason, my pointer won't cout when it comes to the printInventory function. I printed it in the readFile function, but it wont do the same in the printInventory function. can you check it out?

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
  #include <iostream>
#include <string>
#include <cstring>
#include <fstream>


using namespace std;
const int MAX = 81;

void readFile(int count,string ** inventory);
void transaction(int count, string* inventory);
void printInventory(int count, string* inventory);
bool searchAvailablity();

int main()
{
    int count = 0;
    string * inventory;
    readFile (count, &inventory);
    transaction(count, inventory);

    return 0;
}

void readFile(int count,string ** inventory)
{
   string temp;
   char fileName[MAX];
   bool validFile;
   ifstream inFile;

   cout << "Enter the file name: ";
   cin >> fileName;

   inFile.open(fileName);


   while (!inFile){
        cout << "That is not a valid filename. Please enter another filename.";
        cin >> fileName;
        inFile.open(fileName);
        }
    while (getline(inFile, temp))
        count++;

    inFile.clear();
	inFile.seekg(0, ios::beg);

	(*inventory) = new string[count];


    for (int i =0; i < count; i++)
    getline(inFile,*(*(inventory)+i));


	for (int p = 0; p< count; p++)
    cout << *(*(inventory)+p) << endl;
}

void transaction(int count, string* inventory)
{
    bool finished = false;
    while (finished == false)
    {
        printInventory(count, inventory);
        finished = true;

    }
}

void printInventory(int count, string* inventory)
{
    cout << "Current Stock: " << endl;
    for (int i = 0; i< count; i++)
    cout << (*(inventory+i)) << endl;

}
bool searchAvailablity()
{

}
Last edited on
readFile should take count by reference (or by address if you prefer.)
Topic archived. No new replies allowed.