Thread: struct error

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    77

    struct error

    Hello to all,

    I am receiving an error that I do not know how to resolve. Here is the relevant code.

    Code:
    typedef struct DPCell { char rowChar ; char colChar ;  int Score ; struct DPCell *traceBack ; int traceBackType; } DPCell ; 
    
    DPCell **DPArray ;   // 2-D array
    
    
     if ( DPArray.rowChar[i][j] == DPArray.colChar[i][j] )
    Error: request for member ‘rowChar’ in something not a structure or union

    Any suggestions would be great

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    DPArray is a pointer to a pointer of DPCell, try (*DPArray)->rowChar...

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    new error now.

    Code:
     ( (*DPArray)->rowChar[i][j] == (*DPArray)->colChar[i][j] )

    error: subscripted value is neither array nor pointer

    Any suggestions??

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if your 2D array is properly allocated, then it will be
    Code:
    DPArray[i][j].rowChar
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is rowChar or colChar an array? No? Then how do you suggest you access a subscript? Subscript works on pointers and arrays.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    thanks for the help with the last question. however, i have a new problem.

    warning: assignment from incompatible pointer type

    heres the code where the problem is:

    Code:
    bestRowCell.address = & DPArray[i][j] ;
    here is my initialization; which may have an error in them

    Code:
     typedef struct DPCell { char rowChar ; char colChar ;  int Score ; struct DPCell *traceBack ; int traceBackType; } DPCell ; 
    
     DPCell **DPArray ;   // 2-D array
    
    struct { int score ; char * address ;} bestRowCell ;
    ???

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so? char* is really different from struct DPCell*
    compiler is right

    what is your question?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    how do I get bestRowCell.address to contain the address of DPArray[i][j]?

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by gkoenig View Post
    how do I get bestRowCell.address to contain the address of DPArray[i][j]?
    Why do you want to do it? they are of different types...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    my program is generating a 2d array filled with scores. I want to get the highest score in my bottom row and my right-most column and then get the higher of the two.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Match the type. There's no reason you shouldn't.
    It should be DPCell*, not char*.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    thanks for the help. to be continued...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM