Thread: Expression must have a pointer type

  1. #1
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70

    Expression must have a pointer type

    Hi All,

    I'm getting the following error when i try to compile my code.
    "Expression must have a pointer type".
    Code:
    typedef int KEY;
    typedef struct
    {
    KEY authKey;
    }STR;
    
    STR var;
    int userKey = 10;
    var->KEY = userKey;
    I'm getting the error at the last line, where i try to assign the value for the structure variable.

    Thank you in advance.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    If var is not a pointer then you use . to access its members. var.KEY = userKey
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    Thank you very much...
    i know i did some silly mistake only...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data type mismatch in criteria expression ERROR
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-11-2009, 01:21 AM
  2. expression must be of integral type in function main()
    By Panian in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2009, 10:35 AM
  3. Replies: 17
    Last Post: 03-06-2008, 02:32 PM
  4. Replies: 4
    Last Post: 08-27-2007, 11:51 PM
  5. Pointer expression.
    By InvariantLoop in forum C Programming
    Replies: 1
    Last Post: 03-13-2005, 09:35 PM