#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0

    Syntax error with a program


    Hi all!
    I have a problem with this program and I don't understand how to solve it:

    #define N 3
    #define M 128
    #define UK 16

    typedef struct An_employee {
    int age;
    char name[M];
    struct {
    char street[M];
    int number;
    char city[M];
    union {
    int it_zip;
    } zip;
    } address;
    } employee;

    typedef employee employees[N];


    void print_employees(employee a[N]){
    int i;

    for(i=0; i<N; i++){
    printf("employee: %d age: %d\n",i, a[i].age);
    printf("employee: %d name: %d\n",i, a[i].name);
    printf("employee: %d street: %d\n",i,a[i].address.street);
    }

    }


    main()
    { int i;

    for(i=0; i<N; i++)
    {
    Code:
    employees [i].age="0";

    employees [i].name="none";
    employees [i].address.street="nostreet";
    }

    print_employees ()
    scanf("%d");
    }


    at the highlight line, in the main function, appears the error: "syntax error before '[' token". What is it? What can I do?
    Please help me! Thanks all :)
  2. #2
  3. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    39
    No spaces before array square brackets, I suspect.
    The next two lines as well.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by admiraln
    No spaces before array square brackets, I suspect.
    The next two lines as well.
    No, it's the same :(
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by deliabeatles
    No, it's the same :(
    I wrote "static employee employees[N];"
    and now the error is "incompatible types in assignment"...
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    employees [i].age="0";
    employees [i].name="none";
    employees [i].address.street="nostreet";


    Well age isn't even a string, so perhaps
    employees [i].age=0;

    As for the others, try something like
    strcpy(employees [i].name,"none");
    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
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by salem
    employees [i].age="0";
    employees [i].name="none";
    employees [i].address.street="nostreet";


    Well age isn't even a string, so perhaps
    employees [i].age=0;

    As for the others, try something like
    strcpy(employees [i].name,"none");
    Thank you, I solved! ;)

IMN logo majestic logo threadwatch logo seochat tools logo