Hello All,
I am having a problem making my program display and output correctly. When i run my program my count will display but my word will just give me some kind of line. Can you please help me correct this?
Thanks
Ronnie
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//declare a structure and variables
struct node
{
mutable char word[50];
int count;
node *link; //does not have to be called link but must have the struct data type ex: node
};
//Create global variable that is going to represent the head of the list.
node* HeadPointer = NULL;
//Declare function prototypes
void InsertItem( char, int, node * );
void PrintList( node *);
int main ( )
{
char InitWord[50] ="\0";
int InitCount = 0;
node* CurrentRecordPointer = NULL; //represent the new record we keep adding
char NextChar = '\0';
char ContinuationFlag = 'Y';
while (toupper (ContinuationFlag) == 'Y' )
{
cout << "Enter The Word: " << endl;
NextChar = cin.peek( );
if ( NextChar == '\n' )
{
cin.ignore( );
}
cin.get ( InitWord, 50 ) ;
cout << endl;
cout<<"Enter The Count: " << endl;
cin >> InitCount;
//Create a new record
CurrentRecordPointer = new node;
InsertItem (InitWord[50], InitCount, CurrentRecordPointer );
//Set our HeadPointer equal to CurrentRecordPointer, because we just want to keep track of who's at the head of the list
HeadPointer = CurrentRecordPointer;
//ask the user if they want to add more records
cout<<"Do you wish to enter any more items?" << endl;
cout<<"Enter 'Y' or 'N' "<<endl;
cin>> ContinuationFlag;
cout<<endl;
}//end of while loop
//Call the printlist functions to display the items
PrintList ( HeadPointer );
return 0;
}
//function developed
//Insert data into linked list and set link to next node.
void InsertItem (char InitWord, int InitCount, node * CurrentRecordPointer)
{
//CurrentRecordPointer-> ( word, Initword );
CurrentRecordPointer->word[50] = InitWord;
CurrentRecordPointer->count = InitCount;
CurrentRecordPointer->link = HeadPointer;
}
void PrintList ( node* Head )
{
//will do formatting here
while ( Head != NULL )
{
cout<< Head->word[50] << " " << Head->count << endl;
Head = Head->link; //gets a next record
}
}