really don't know how to do this

This is a discussion on really don't know how to do this within the C++ Programming forums, part of the General Programming Boards category; This is a task which was said to be easy, but hours went, I'm still here... I'm dealing with the ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Post really don't know how to do this

    This is a task which was said to be easy, but hours went, I'm still here...

    I'm dealing with the char array in the stack. I need to reverse the chars except for those in double quotes.

    If the line has quotes, then my program would fail. I do have trouble outputing the chars in the array in its original order. Appreciate for any help...

    ---------------------------------------
    // read on char at a time, put it in Stack1
    //
    for (int i = 0; i < size; i++)
    {
    switch (state) {

    case reverseLine:

    if ( A[i] == ' ' || A[i] == '\t' ) {

    ;
    }

    else if ( A[i] != '\"') {
    pushStack(Stack1, A[i]);
    cout << "No Quote!" << endl;
    //cout << popStack(Stack1) <<endl;
    state = reverseLine;
    }

    else {
    pushStack(Stack1, A[i]);
    //cout << popStack(Stack1);
    state = QuoteWords;
    }
    //cout << "I'm here!";
    //cout << popStack(Stack1) << endl;
    break;

    //!!!MY BIG PROBLEM IN THIS STATE
    case QuoteWords:

    if ( A[i] != '\"') {
    //cout << "QuoteWords!" << endl;

    cout << A[i];
    state = QuoteWords;
    }

    else if ( popStack(Stack1) == '\"') {
    pushStack(Stack1, A[i]);
    cout << popStack(Stack1);
    state = reverseLine;
    }
    else
    state = QuoteWords;

    break;

    }

    }

    for (int i=0;i < size; i++)

    cout << popStack(Stack1) << endl;
    }

    -------------------------------------------
    ex. input: happy "day" one
    output should be eno "day" yappy

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    sorry, typo...

    input: happy "day" one
    output: eno "day" yppah

    thanks for reading...

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Do you really have to use a stack for this?

    if you do then you will need to pop() into another stack or array etc. until you hit the other " then print out that stack/array. I think you get the idea.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Thank you. That's a great hint. I will work on it.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21