matrix indexes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tal23
    New Member
    • Oct 2008
    • 4

    matrix indexes

    I wanted to use matrixs in awk and got some problem, here is some of the script code, from the BEGIN tag:
    Code:
    row_char[1]="a";row_char[2]="b";row_char[3]="c";row_char[4]="d";row_char[5]="e"$
    row_char[8]="h";row_char[9]="i";row_char[10]="j";row_char[11]="k";
    # from the proccess passage:
    sentence[varchar[11],1]=1;
    diffrence=4;
    i=7;
    sum_index=diffrence+i;
    printf("test: %d",sentence[row_char[11],1]); # it prints that like it should be test: 1
    printf("test2: %d",sentence[row_char[sum_index],1]); # here it prints test2: 0 that does not right.
    I almost sure the problem is the form of the array index ,as in awk probably there is no matrixs.
    Please help me with this.
    Last edited by Nepomuk; Oct 27 '08, 03:47 PM. Reason: Please use [CODE] tags!
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi tal23! Welcome to bytes.com!

    It's great to have you here!

    When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags. In this case I added them for you - your question was very difficult to read without them.

    I'm sorry to say, that I can't help you with your question, but I'm sure someone will.

    Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

    Greetings,
    Nepomuk (Moderator)

    Comment

    • tal23
      New Member
      • Oct 2008
      • 4

      #3
      That is only a passages from the script but it can run like a script even in this shape.
      the important part from the begin passage:
      Code:
      BEGIN
      {
      row_char[1]="a";row_char[2]="b";row_char[3]="c";row_char[4]="d";row_char[5]="e"$ 
      row_char[8]="h";row_char[9]="i";row_char[10]="j";row_char[11]="k"; 
      }
      # from the proccess passage: 
      {
      sentence[varchar[11],1]=1; 
      diffrence=4; 
      i=7; 
      sum_index=diffrence+i; 
      printf("test: %d",sentence[row_char[11],1]); # it prints that like it should be test: 1 
      printf("test2: %d",sentence[row_char[sum_index],1]); # here it prints test2: 0 that does not right. 
      }
      The problem i need to solve is the value that been printed in the two printf sentences one showes a right result and one wrong but i must use the syntax of the second
      Last edited by Nepomuk; Oct 28 '08, 03:32 PM. Reason: Added [CODE] tags

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Hi!
        As I said before, please use the [CODE]...[/CODE] tags when posting code - just put the word [CODE] before your code and [/CODE] after it. Alternatively, use the # button in the message box. I've added those tags for you twice in this thread now.

        Now, about your question: Try printing the value of sum_index - is it really 11, as it should be? I don't see any reason, why it shouldn't be, but you never know...

        Greetings,
        Nepomuk

        Comment

        • tal23
          New Member
          • Oct 2008
          • 4

          #5
          It has that value for sure.

          Comment

          Working...