String

I have to enter two words into this program and everytime i hit the spacebar, and another letter then enter. My program flips out. Thanks

struct node
{
string word;
int count;
node *link; //pointer to the next record

};

then in main...

string InitWord = "\0";
int InitCount = 0

Nothing wrong with that code. Perhaps the problem is elsewhere in your code.
if you are doing it like:
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

int initCount = 1;
string initWord;
char responce;
bool Done = false;

while(Done != true)
{
      node *pNewNode = new node;

      cin >> initWord;
      node->word = initWord;
      node->count = initCount;
      node->link = null;

      // assuming you append it to the end of the list...

      do
      {
            cout << "Would you like to do another one?" << endl;

            cin >> response;

      }while(cin.fail())

      if(response == 'n')
      {
             Done = true;
      }
      initCount++;
}


A space would cause a problem if you didn't check the first cin like the second one.
Topic archived. No new replies allowed.