Pointer syntax in if statement

This is a discussion on Pointer syntax in if statement within the C Programming forums, part of the General Programming Boards category; Is it alright to use a pointer like this in an if else statement? if ((*tPtr) < GRADE_D) *cGPtr = ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    Pointer syntax in if statement

    Is it alright to use a pointer like this in an if else statement?

    if ((*tPtr) < GRADE_D)
    *cGPtr = "D";

    assuming that GRADE_D is a data which has been defined with #define

    I get an error where thye tell me that "=" is missing.
    Only by the cross are you saved...

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    if GRADE_D is a charater and tPtr points to a character then the if statement is fine. (note that 'D' is a character and "D" is a string). The next line looks dubious... did you mean:

    *cGPtr = 'D';

    ?
    DavT
    -----------------------------------------------

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    er...actually
    GRADE_D was defined as an integer, e.g. 50

    whereas *tPtr was defined as a double type pointer, which contains an address to a double value.

    the error message with this is

    error C2143: syntax error : missing ')' before ';'

    and

    error C2059: syntax error : ')'

    the line i have now looks like this :

    if (*tPtr < GRADE_D)
    *cGPtr = 'D';
    Only by the cross are you saved...

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    also, if i replace the GRADE_D with a directly written integer like 50 or 88, it works...
    seems like there's a problem with the #define thing

    but i defined it correctly like

    #define GRADE_D 50;
    Only by the cross are you saved...

  5. #5
    Banned
    Join Date
    May 2003
    Posts
    124
    > #define GRADE_D 50;
    Replace the semicolon at the end, because #define is a preprocessor directive and doesn't need ";" at the end.

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    hey thanx man! that worked for me!
    Only by the cross are you saved...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. Replies: 3
    Last Post: 01-25-2006, 09:30 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

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