NEED HELP WITH JUMBLE WORD PRGRAMM

I don't know what's wrong with my code. i had to compare each jumble word from file to the dictionary word in another file and if they matched...i had to print it out...I have written this code in xcode...but it does not display any output nor it says there is any problem with this code....NEED HELP...!!

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
// dynStrings.cpp
// dynamic string array
// use with any file of strings

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h> // needed for exit() function
using namespace std;
const int INITIAL_CAP = 5;

string * upsize( string *old, int &cap );


string sortdictword( string word)
{
    string sortedDicword = word;
    sort(sortedDicword.begin(), sortedDicword.end());
    return sortedDicword;
}


string sortjumb( string word)
{
    string sortedJumword = word;
    sort(sortedJumword.begin(), sortedJumword.end());
    return sortedJumword;
}


int main ( int argc, char **argv)
{
	ifstream infile;
    
	infile.open ( "dictionary.rtf",  ios::in  );  // opening dictionary file
	if (!infile) exit(0);
	string *dict = new string[INITIAL_CAP];
	int dCnt=0, dCap=INITIAL_CAP;
	while (infile >> dict[dCnt] )
	{
		dCnt++;
		if ( dCnt == dCap )
		{
			dict = upsize( dict, dCap );
		}
	}
    infile.close();
    
    
	infile.open ( "jumbles.rtf",  ios::in  );  // opening jumbles file
	if (!infile) exit(0);
	string *jumb = new string[INITIAL_CAP];
	int jCnt=0, jCap=INITIAL_CAP;
	while (infile >> jumb[jCnt] )
	{
		jCnt++;
		if ( jCnt == jCap )
		{
			jumb = upsize( jumb, jCap );
		}
	}
    
    infile.close();
	   
    for ( int i = 0; i < jCnt && i < dCnt; i++)
    {
     
        sortjumb(jumb[i]);
        sortdictword(dict[i]);
        
        
        if (sortdictword == sortjumb)
            
        {
            cout << jumb[i] << "     " << dict[i] << endl;
        }

        
    }
    
    return 0;
    
} // END MAIN

// allocate new arr 2 x big as the old arr
// copy all the data from the old to the new
// free the old arr
// update cap to be x 2
// return addr of new arr

string * upsize( string *old, int &cap )
{
	string* bigger = new string[ cap * 2 ];
	for ( int i=0 ; i<cap; i++)
		bigger[i] = old[i];
	cap *=2;
	return bigger;
}
Isn't std::sort() declared in <algorithm> ?
Your compiler should complain that ?
I didn't get it...but,..it says build succeed...and it shows no error...but also no output...plz help...i #include <algorithm> also...but it's not seems to be working...
is "jumbles.rtf" really a .rtf file, if yes, save it again as a plain text file ( .txt )

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
// dynStrings.cpp
// dynamic string array
// use with any file of strings

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h> // needed for exit() function
#include <algorithm>


using namespace std;

const int INITIAL_CAP = 5;

string * upsize( string *old, int &cap );


string sortdictword( string word)
{
    string sortedDicword = word;
    sort(sortedDicword.begin(), sortedDicword.end());
    return sortedDicword;
}


string sortjumb( string word2)
{
    string sortedJumword = word2;
    sort(sortedJumword.begin(), sortedJumword.end());
    return sortedJumword;
}

int main ( int argc, char **argv)
{
	ifstream infile;
    
	infile.open ( "dictionary.txt",  ios::in  );  // opening dictionary file
	if (!infile) exit(0);
	string *dict = new string[INITIAL_CAP];
	int dCnt=0, dCap=INITIAL_CAP;
	while (infile >> dict[dCnt] )
	{
		dCnt++;
		if ( dCnt == dCap )
		{
			dict = upsize( dict, dCap );
		}
	}
    infile.close();
    

    
    
	infile.open ( "jumbles.txt",  ios::in  );  // opening jumbles file
	if (!infile) exit(0);
	string *jumb = new string[INITIAL_CAP];
	int jCnt=0, jCap=INITIAL_CAP;
	while (infile >> jumb[jCnt] )
	{
		jCnt++;
		if ( jCnt == jCap )
		{
			jumb = upsize( jumb, jCap );
		}
	}
    
    
    infile.close();
    
    for ( int i = 0; i < jCnt && i < dCnt; i++)
        
    {
        sortdictword(dict[i]);
        sortjumb(jumb[i]);
        if (sortdictword == sortjumb)
        {
            cout << jumb[i] << "     " << dict[i] << endl;
        }
        
    }
    
    return 0;
    
} // END MAIN

// allocate new arr 2 x big as the old arr
// copy all the data from the old to the new
// free the old arr
// update cap to be x 2
// return addr of new arr

string * upsize( string *old, int &cap )
{
	string* bigger = new string[ cap * 2 ];
	for ( int i=0 ; i<cap; i++)
		bigger[i] = old[i];
	cap *=2;
	return bigger;
}


Here is my code....I changed .rtf file to .txt file...but still no progress...:(!!
Last edited on
1
2
3
4
5
6
7
8
while (infile >> dict[dCnt] )
	{
		dCnt++;
		if ( dCnt == dCap )
		{
			dict = upsize( dict, dCap );
		}
	}

i think should be :
1
2
3
4
5
6
7
8
while (infile >> dict[dCnt] )
	{
		if ( dCnt == dCap )
		{
			dict = upsize( dict, dCap );
		}
                dCnt++;
	}


and also the one in while (infile >> jumb[jCnt] ) {
Last edited on
My output says... "Program ended with exit code: 0"..!!
Topic archived. No new replies allowed.