need help!!!

This is a discussion on need help!!! within the C++ Programming forums, part of the General Programming Boards category; I need to have the program take a user's input in prefix notation and display it in a left child-right ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    7

    need help!!!

    I need to have the program take a user's input in prefix notation and display it in a left child-right child array representation of a tree.

    Ex: input: *2x
    output:
    * 1 2
    2 0 0
    x 0 0

    the first column representing the elements, the second column refers to the left child while the third column refers to the right child.

    The problem I am having is getting the input to read the input as 3 different characters so they can be displayed in array[0][0], array[1][0], and array[2][0]. I must only use one 2 dimensional array.

    If a link to the problem would be helpful its
    CSCI 3080 Fall 2009 OLA 2

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So read one character at a time into array[something][0].

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    7
    ok so how would I then output the elements the user inputs into the left column. Do I need a for loop or how would do I need to go about it?

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    yes definitely for 2D array reading you should have a loop

    like in your case

    Code:
    #include <stdio.h>
    
    int main() {
      char arr[][3]  = {{'*', '1', '2'},
                        {'2', '0', '0'},
                        {'x', '0', '0'}
                       };
      int row = 0;
      int col = 0;
      for (; row < 3; ++row) {
        col = 0;
        for (; col < 3; ++col) {
          printf("%c", arr[row][col]);
        }
        printf("\n");
      }
      return 0;
    }
    [rocky@localhost test]$ ./a.out 
    *12
    200
    x00
    [rocky@localhost test]$
    may be this can help you out

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