loop output weird problem

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
#include <iostream>
#include <string>
using namespace std;

class Hash
{
        public:
        int locatePos(string, int);
        void init(string *, int length);
        void put(string *, string, int, int);
        void output(string *, int);
};

void Hash::output(string *sarray, int length)
{
	int k;
        for(k = 0; k < length; k++);
        {
		cout << sarray[k] << " ";
        }
        cout << endl;
}

int Hash::locatePos(string s, int length)
{
        return ((s[0] + s[s.length()-1])%length);
}

void Hash::put(string *sarray, string s, int pos, int origPos)
{
        if(pos == 23)
                pos = 0;
        if(pos == origPos)
	{
		if(sarray[pos].compare("?") == 0)
	                sarray[pos].assign(s);
                return;
	}
        if(sarray[pos].compare("?") == 0)
                sarray[pos].assign(s);
        else
                this->put(sarray, s, pos+1, origPos);
}

void Hash::init(string *s, int length)
{
        int n=0;
        while(n < length)
        {
                s[n] = "?";
                n++;
        }
}

int main(void)
{
        string s;
        int num, i = 0;
	Hash hash;
        string sarray[23];
        cout << "Enter 15 strings."<<endl;
        hash.init(sarray, 23);
        while(i < 15)
	{
                cout << i <<endl;
                cin >> s;
                hash.put(sarray, s, hash.locatePos(s, 23), hash.locatePos(s, 23)-1);
                i++;
        }
//	for(int j = 0; j < 23; j++)
//	{
//		cout << sarray[j] << " ";
//	}
        hash.output(sarray, 23); //dosent work
}
Output method has something funky going wrong with it. The commented code in the main function works to the same effect that the output function should.
Last edited on
It might be a good idea to use string[] as your argument instead of string*.

-Albatross
Dosen't matter... still does the same thing.
Topic archived. No new replies allowed.