STRUGGLING!! I am in dire need of some help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 6
Reputation: drake2212 is an unknown quantity at this point 
Solved Threads: 0
drake2212 drake2212 is offline Offline
Newbie Poster

STRUGGLING!! I am in dire need of some help

 
0
  #1
29 Days Ago
I am in desperate need of help! I am having an issue inserting the word into the correct list. Each array index is a letter of the alphabet, and the words need to be put into the correct index according to the first letter of the word. Can I get some help with fixing this issue with my insertWord function?

Here is the text file I am using:

I am excited to be taking this class. Programming isn't
easy but I feel I am getting better. One day when I am
out of the military I hope to work for some IT business.
The job can't be part-time either!
67dd a09dd.

Here is the program file:


# include <iostream>
# include <iomanip>
# include <fstream>
# include <string>
# include <cctype>
# include <cstddef>

using namespace std;

const int MAX_SIZE = 26;

struct wordRec {
string newWord;
wordRec *previous;
wordRec *next;
};

void programIntro();
wordRec* initializeList ();
void initializeArray (wordRec *[], int& index);
void readTextFile (ifstream& wordIn, wordRec *letters[], int& index, int& wrdIndex);
void checkInputWord (ifstream& wordIn, string& word);
void insertWord (ifstream& wordIn, wordRec* [], int& index, string& word, int& wrdIndex);
void wordListPlacement (ifstream& wordIn, wordRec *letters[], int& index, int& wrdIndex);

int main (int argc, char* argv[]) {

wordRec* letters[MAX_SIZE];
wordRec *head = NULL;

int count;
int indexes;
int wordCount;
string words;
int wordIndex;

ifstream wordIn;

wordIn.open (argv[1]);

if (!wordIn) {
cout << "Error! Text File did not open!" << endl;
system ("pause");
return 1;
}
else
initializeArray (letters, indexes);
readTextFile (wordIn, letters, indexes, wordIndex);
wordIn.close ();

system ("pause");
return 0;
}

void initializeArray (wordRec *letters[], int& index)

{
for (index = 0; index < MAX_SIZE; index++) {
letters[index] = NULL;
}

return;
}

void readTextFile (ifstream& wordIn, wordRec *letters[], int& index, int& wrdIndex)

{
wordRec *head = letters[index];
string word;
char character;
char letter;

while (wordIn) {
wordIn >> word;

// calculates the specific list each word will go into
character = word[0];
letter = toupper(character);
wrdIndex = letter - 'A';

// checks the word format for errors
checkInputWord (wordIn, word);

// uppercases all the words in the file
for (int indx = 0; indx < word.size(); indx++) {
word[indx] = static_cast<char>(toupper(word[indx]));
}

insertWord (wordIn, letters, index, word, wrdIndex);
}
return;
}

void checkInputWord (ifstream& wordIn, string& word)

{

// strips off any punctuation if there is any
for (int index = 0; index < word.length(); index++) {
if ((ispunct(word[index])) && (word[index] != '\'') && (word[index] != '-')) {
word.erase(index);
}
}

// ignores the word if it contains any digits and does not add it to the list!
for (int index = 0; index < word.size(); index++) {
if (isdigit (word[index])) {
wordIn.ignore (word[index], word.length() );
}
}

return;
}

void insertWord (ifstream& wordIn, wordRec *letters [], int& index, string& word, int& wrdIndex)

{
wordRec *head = NULL;
wordRec *newNode = NULL;

if (head == NULL) {
newNode = new (nothrow) wordRec;
newNode->newWord = word;
newNode->previous = NULL;
newNode->next = newNode;

if (head != NULL)
head->previous = newNode;

head = newNode;
letters[index] = head;
letters[index]->next = head;
letters[index]->previous = head;

}
return;
}
Last edited by drake2212; 29 Days Ago at 11:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 39
Reputation: niXman is an unknown quantity at this point 
Solved Threads: 10
niXman's Avatar
niXman niXman is offline Offline
Light Poster
 
0
  #2
29 Days Ago
Please format code, and paste in the tags.
Я из Молдавии. Говорю на Русском.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 323
Reputation: Clinton Portis is an unknown quantity at this point 
Solved Threads: 34
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Whiz
Join Date: May 2006
Posts: 1,827
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 118
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso
Reply

Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC