struct error

This is a discussion on struct error within the C Programming forums, part of the General Programming Boards category; Hello to all, I am receiving an error that I do not know how to resolve. Here is the relevant ...

  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
    395
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    if your 2D array is properly allocated, then it will be
    Code:
    DPArray[i][j].rowChar
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,901
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    so? char* is really different from struct DPCell*
    compiler is right

    what is your question?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    Posts
    22,901
    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, 09:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 10:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 04: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, 02:27 PM

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