error: expected ')' before

This is a discussion on error: expected ')' before within the C Programming forums, part of the General Programming Boards category; I'm writing a program where I have to read in information from a data file into an array of structures ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    5

    error: expected ')' before

    I'm writing a program where I have to read in information from a data file into an array of structures then print it out in a formatted chart. I'm getting these error messages when I try to compile and I can't figure out how to get rid of them. I know I'm missing something simple but I'm just not seeing it:

    trip.c:17: error: expected ')' before 'legs'
    trip.c:55: error: expected ')' before 'legs'
    trip.c: In function 'GetGasInfo':
    trip.c:92: warning: format '%lf' expects type 'double *', but argument 2 has type 'double'
    trip.c:94: warning: format '%lf' expects type 'double *', but argument 2 has type 'float *'

    Thank you for your time.
    Last edited by AKeiTyrian; 04-13-2008 at 06:51 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I would guess there may be something wonky with your definition of LEG.

    Also: scanf requires pointers, and since pMileage is a pointer, you should pass it. To read into a float variable, you must not use %lf, you must use %f.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Thanks.
    Last edited by AKeiTyrian; 04-13-2008 at 05:45 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You are including the appropriate header where this struct is defined, yes? Otherwise the compiler doesn't know what LEG means.

    Once you fix that, you'll get a new set of errors, but those are easy to fix.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Yeah, the correct header is there.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by AKeiTyrian View Post
    Yeah, the correct header is there.
    Well, where? You appear to have the struct defined in main.c. You should have a header like "leg.h" which contains just the typedef struct LEG thing, and then included (via #include "leg.h") in your other .cpp file.

    Remember: source files are compiled completely separately from each other. Any data structures and the like have to appear in every source code file they are used in.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Thanks. That helped a lot.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,663
    http://cpwiki.sourceforge.net/A_pointer_on_pointers
    Don't neglect the pointers! They are very important to handle right!
    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.

Popular pages Recent additions subscribe to a feed

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