Expression must have a pointer type

This is a discussion on Expression must have a pointer type within the C Programming forums, part of the General Programming Boards category; Hi All, I'm getting the following error when i try to compile my code. "Expression must have a pointer type". ...

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

    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
    66
    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-28-2007, 12:51 AM
  5. Pointer expression.
    By InvariantLoop in forum C Programming
    Replies: 1
    Last Post: 03-13-2005, 09:35 PM

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