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...!!
// dynStrings.cpp
// dynamic string array
// use with any file of strings
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h> // needed for exit() function
usingnamespace std;
constint 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;
}
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...
// 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>
usingnamespace std;
constint 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...:(!!