Thread: help me

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    7

    help me

    im tierd, and making mistakes, i cant see the error in my header file...please help.


    header
    Code:
     
    #include <stdio.h>
    #define labor 0.35
    #define tax .085
    int main (void);
    void  getnum (float *le, float *wi, float *di, float *co);
    void calc1(float ln, float wd, float ds, float cs, float *area, float
    *carpet, float *labor, float *install, float *discount, float *subt, float *total);
    void calc2(float len, float wid, float cos, float *are, float *car, float *lab, float *ins);
    void calc3(float carp, float labo, float inst, float dcs, float *disc, float *subto);
    void calc4(float subs, float *totalf);
    main file
    Code:
    #include "my.h"
    
    int main (void)
    
    {
    // Local Declarations
    float l;
    float w;
    float d;
    float c;
    float ar;
    float ca;
    float la;
    float in;
    float dis;
    float su;
    float to;
    //Statements
    
    //Get the input form the user
    getnum(&l,&w,&d,&c);
    calc1(l,w,d,c,&ar,&ca,&la,&in,&dis,&su,&to);
    print1(l,w,d,c,ar,ca,la,in,dis,su,to);
    return 0;
    }
    error
    Code:
    -bash-3.00$ gcc -c main.c
    In file included from main.c:1:
    my.h:7: error: syntax error before numeric constant

    its probably obvious to you guys

    warthog

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Use header guards in your header.
    Code:
    #ifndef MY_HEADER_H
    #define MY_HEADER_H
    /* Your code here */
    #endif
    Your problem is you're defining labor as a numeric constant (0.35) and later in your calc1() function you declare a pointer as labor. When the preprocessor is done with this you now have
    Code:
    float *0.35
    Rename the variable.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    thanx man,

    stupid mistake on my part

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    A little tip for debugging manually... when you have a big long line like that full of declarations. Break the error
    line down into seperate lines then compile again to get a more clear look at the error.

    Code:
    void calc1(float ln, float wd, float ds, float cs, float *area, float
    *carpet, float *labor, float *install, float *discount, float *subt, float *total);  /*Here is the error */
    Code:
    void calc1(float ln, float wd, float ds, float cs, float *area, float *carpet, 
    float *labor,  /* Here is the error */
    float *install, 
    float *discount, 
    float *subt, 
    float *total);
    Sent from my iPadŽ

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    ...and/or adopt the convention of using uppercase for macros.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    7

    problem # 2

    ok, ive compiled the program, and in the assignment, we are not supposed to prompt the user. Instead, we save numbers in a file called "mydata"

    then when running the program we type in ./a.out<mydata

    and its is supposed to crunch the numbers

    instead im getting segmintation fault

    warthog

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Any number of things could have went wrong, but you need to rewrite main() to accept command line arguments, and then write the file you want to use.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    i dont know how to make main accept post line arguments

    how do i do this

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    heres the get data code

    [code]

    #include "my.h"
    void getnum (float* le, float* wi, float* di, float* co)
    {

    //local declarations
    float len;
    float wid;
    float dis;
    float cos;

    //Statements

    scanf("%f %f %f %f\n",len,wid,dis,cos);

    return;
    }

    [\code]

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Your code tag syntax is wrong. It should look like this:

    Code:
    // first line of code
    // last line of code

    The outcome would look like this:

    Code:
    printf("Created in code tag format

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    [/CODE] not [\CODE].
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    Quote Originally Posted by swgh
    Your code tag syntax is wrong. It should look like this:

    Code:
    // first line of code
    // last line of code

    The outcome would look like this:

    Code:
    printf("Created in code tag format

    im still not exactly sure what you are saying.....
    do i put that in main.c?

Popular pages Recent additions subscribe to a feed