Thread: Weird error message

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    18

    Weird error message

    When I try to compile my C program, I'm getting this error message.... Any thoughts?

    Project1v4.c:81: error: expected ‘;’, ‘,’ or ‘)’ before ‘.’ token
    Project1v4.c:102: error: expected ‘;’, ‘,’ or ‘)’ before ‘.’ token
    Code:
    int InObject(char shape.type, int p.x, int p.y, int shape.arg0, int shape.arg1, int shape.arg2) {
    }
    int CheckArgs(char shape.type, int shape.color.red, int shape.color.green, int shape.color.blue, int shape.arg0, int shape.arg1, int shape.arg2, int numArgs) {
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yes, you have dots in all your variable names.

    You're only allowed dots when you're specifically referring to members of a struct/union/class.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    I know, all of those variables ARE in structs!

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I believe Salem is going for his Wizards "know it all" title, but for the rest of us mere mortals, we need to see more of the relevant code.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    This is the InObject function that creates the error message.

    Code:
    int InObject(char shape.type, int p.x, int p.y, int shape.arg0, int shape.arg1, int shape.arg2) {
       if (shape.type == 'R') {
          return Rectangle(shape.arg0, shape.arg1, p.x, p.y);
       }
       if (shape.type == 'C') {
          return Circle(shape.arg0, p.x, p.y);
       }
       if (shape.type == 'E') {
          return Ellipse(shape.arg0, shape.arg1, shape.arg2, p.x, p.y);
       }
       if (shape.type == '!') {
          return Exclaim(shape.arg0, shape.arg1, p.x, p.y);
       }
       if (shape.type == 'H') {
          return LetterH(shape.arg0, shape.arg1, p.x, p.y, shape.arg2);
       }
       if (shape.type == 'L') {
          return LetterL(shape.arg0, shape.arg1, p.x, p.y, shape.arg2);
       }
    }

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    And Salem's original advice remains correct. Variable or argument names with a . are invalid in C.

    If you want to pass a struct to a function, pass that struct (by value or by pointer) as a single argument.

    If the caller retrieves values of struct members in order to pass them to a function, the function does not need to know that.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by cpsestudent View Post
    I know, all of those variables ARE in structs!
    But do you know that inside the function, that makes no difference at all?

    For example:
    Code:
    struct tTest
      { int x;
         int y; }
     
    // do a multiply
    int multiply(int a, int b)    //--- note the variable names here
      { return a * b;  }
    
    int main (void)
      { int z; 
        struct tTest test;
         test.x = 10;
         test.y = 5;
        
        z =  multiply(test.x,test.y);
    
        Printf("%d\n" , z);   
      
        return 0; }
    Note that in multiply() you *cannot* use dotted varaible names. C doesn't know what to do with that. You can pass in a dotted name such as test.x when calling the function but you cannot put the dotted names in a function's parameter list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird loop keep happeneing....pls help debug...
    By Diamonddrago in forum C Programming
    Replies: 5
    Last Post: 11-18-2009, 11:51 PM
  2. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 11:23 PM
  3. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  4. weird error
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 07-17-2005, 07:32 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM

Tags for this Thread