No compile errors, but blank screen on execute.

Hey guys, I'm working on a Hash Table implementation and after fixing all the errors and finally getting it to compile and link correctly, I am met with a black screen upon execute. Is there anything that you guys can spot that I have missed? I appreciate it.

main.cpp
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
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include "HashTab.h"

using namespace std;

void runPrompt();
void add(string f, string l, string id,
         string c, string m);
void rem(string cid);
void print();
void error(string s);

HashTab* hashtab;

//this is where i will store the string tokens
string strarray[10];

int main()
{
    cout << "debug me" << endl;
	runPrompt();
}

void runPrompt()
{
	string input;
	int index;

	while(input != "quit")
	{
	    index = 0;
		cout << "set> ";
		//get the input and split into iss stream
		getline(cin,input);
		istringstream iss(input);

		while(iss)
		{
			//gather strings delimited by ' ' and store in array
			//index starts at 0, so increment after
			iss >> strarray[index];
			index++;
		}

		if(input.find("add") != string::npos)
		{

			//add customer id, first name, last name
			//strarray[0] = 'add'
			//[1] = fname, [2] = lname, [3] = id
			//[4] = classyear, [5] = major
			add(strarray[1], strarray[2], strarray[3],
			strarray[4], strarray[5]);
		}

		if(input.find("remove") != string::npos)
		{
			//remove
			//strarray[0] = remove
			//[1] = id
			rem(strarray[1]);
		}


		if(input.find("print") != string::npos)
		{
			print();
		}

		if(input.find("quit") != string::npos)
		{
		    //free up space
			break;
		}

		if(input.find("quit") == string::npos && input.find("print") == string::npos
     && input.find("remove") == string::npos && input.find("add") == string::npos)
		{
			error(input);
		}
	}
}



void print()
{

}

void add(string f, string l, string id, string c, string m)
{
    hashtab->addelm(f, l, id, c, m);
}

void rem(string num)
{

}

void error(string input)
{
		cout << "Error!  Command not found: " << input <<endl;
}


HashTab.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include "Element.h"

using namespace std;

class HashTab
{
    public:
        HashTab();
        void addelm(string fname, string lname, string id,
            string year, string major);
    private:
        Element* elarray[10];
};


HashTab.cpp
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
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>

#include "Element.h"
#include "HashTab.h"

using namespace std;

HashTab::HashTab()
{

}

//int main()
//{
//	return 0;
//
//}

void HashTab::addelm(string fname, string lname, string id, string year, string major)
{
    //convert id to int
    int sid = atoi(id.c_str());

    //hash according to student id
    int key = sid % 10;

    //-1 means spot hasnt been used
    if(elarray[key]->getKey() == -1)
    {
        //set data and store key in element
        elarray[key]->setstudentdata(fname, lname, sid, year, major);
        elarray[key]->setKey(key);
    }

    else
    {
        for( int j = 0; j < 10; j++)
        {
            key = (key + ((j^2))) % 10;

            if(elarray[key]->getKey() == -1)
            {
                elarray[key]->setstudentdata(fname, lname, sid, year, major);
                elarray[key]->setKey(key);
                break;
            }

            else
            {
                cout << "Error! duplicate student id" << endl;
            }
        }


    }

}


Element.h
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
#include <stdio.h>
#include <string.h>
#include "Element.h"
#include "Student.h"

using namespace std;

Student* s = NULL;

//int main()
//{
//	return 0;
//
//}

Element::Element()
{
    key = -1;
}

int Element::getKey()
{
    return key;
}

void Element::setKey(int i)
{
    key = i;
}

void Element::setstudentdata(string f, string l, int i, string c, string m)
{
    s->set_data(f, l, i, c, m);
}

Student* Element::getdata()
{
    return s;
}


Element.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef ELEMENT_H
#define ELEMENT_H

#include <iostream>
#include <string>
#include "Student.h"


using namespace std;

class Element
{
    public:
        Element();
        int getKey();
        void setKey(int i);
        Student* getdata();
        void setstudentdata(string f, string l, int i, string c, string m);

    private:
        int key;
};

#endif // ELEMENT_H 


Student.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <string>
#include "Student.h"

using namespace std;

//int main()
//{
//	return 0;
//
//}

Student::Student()
{
}

void Student::set_data(string f, string l, int i, string c, string m)
{
    fname = f;
    lname = l;
    major = m;
    classyear = c;
    id = i;
}


Student.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef STUDENT_H
#define STUDENT_H

#include <string>

using namespace std;

class Student
{
    public:
        Student();
        void set_data(string f, string l, int i, string c, string m);

    private:
        string fname;
        string lname;
        string major;
        string classyear;
        int id;
};

#endif // STUDENT_H 


I tried inserting a debug statement in the main() function to see, and it wouldn't even print out the message "debug me" on the screen.

I am using Code::Blocks on Windows with the mingw32-g++.exe compiler. Here is my build log:

1
2
3
4
5
6
7
8
9
10

mingw32-g++.exe -Wall  -g     -c D:\Media\Desktop\Hash\Element.cpp -o obj\Debug\Element.o
mingw32-g++.exe -Wall  -g     -c D:\Media\Desktop\Hash\HashTab.cpp -o obj\Debug\HashTab.o
mingw32-g++.exe -Wall  -g     -c D:\Media\Desktop\Hash\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -Wall  -g     -c D:\Media\Desktop\Hash\Student.cpp -o obj\Debug\Student.o
mingw32-g++.exe  -o bin\Debug\Hash.exe obj\Debug\Element.o 
obj\Debug\HashTab.o obj\Debug\main.o obj\Debug\Student.o   -mwindows  
Output size is 1.06 MB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings (0 minutes, 2 seconds)


If there is any other information I can provide, please let me know.
closed account (Dy7SLyTq)
a) initialize the string on line 29 of input
a) initialize the string on line 29 of input 

Thanks, it is now:
string input = "";

The output is still the same black screen.
Anyone have ideas? This is bugging the crap out of me.
DTSCode wrote:
a) initialize the string on line 29 of input
What do you mean? It is already initialized by the default constructor.
@LB: Yeah I figured it wouldn't do anything, but it was worth a shot.
> Anyone have ideas?
$ gdb Hash.exe
> run
<C-c>
> backtrace
@ne555:
I loaded it up in gdb, and ran the "run" command. It didn't crash and is just left sitting with the blinking cursor on the screen, which doesn't let me run the "backtrace" command.
That's why I wrote `<C-c>' ( ^C ctrl+c )
Interrupt your program
Last edited on
@ne555:

Ctrl+c does nothing to interrupt the program. I tried several times in the gdb prompt and nothing happened. I verified that it worked in other command prompt windows, but not in the gdb one. Does running windows have anything to do with it?
probably, windows sucks.
may try http://www.mingw.org/wiki/Workaround_for_GDB_Ctrl_C_Interrupt
may use some features that your IDE provides (like a "pause" button)
or set a breakpoint at the beginning of main, and execute step by step.
So after testing it on a different machine, I can confirm that the code actually runs. The problem was my IDE and something must have been broken somewhere in the install. Sorry for the trouble guys. I'm going to mark this as solved since I figured out why it blank-screened.
Topic archived. No new replies allowed.