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

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Problem with struct


    please am new to c... i want t o creat a sructure contains some item but wehen i try to call store alues in the structure variable i get this error ...expected ')' before '.' token


    #include<stdio.h>
    #include<string.h>

    struct student
    {
    int id;
    char name[20];
    char dept_name[10];
    float cgpa;
    char sex;

    } ;


    struct student st1;

    strcpy(st1.name ,"TEMITOPE");
    st1.cgpa= 3.59;
    strcpy(st1.dept_name,"COMPTUER_ENGINEERING");
    st1.id=12532;
    st1.sex='M';


    main()

    {
    printf("student name is %s" ,st1.name );
    }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,088
    Rep Power
    2222
    Executable statements must be inside a function; executable statements outside of a function are not allowed!

    Those five lines of executable code between the declaration of st1 and the main() function are not in a function. Either create a function for them or place them in the main() function.

    Also:
    Use code tags!

    You are implicitly declaring main to return int, but then you do not return anything. Declare main as:
    int main()
    and then make the last statement in main():
    return 0;
    That tells the operating system that your program ran successfully. If you need to exit the program because an error kept it from running successfully, then return an non-zero value. That is how things work.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by dwise1_aol
    Executable statements must be inside a function; executable statements outside of a function are not allowed!

    Those five lines of executable code between the declaration of st1 and the main() function are not in a function. Either create a function for them or place them in the main() function.

    Also:
    Use code tags!

    You are implicitly declaring main to return int, but then you do not return anything. Declare main as:
    int main()
    and then make the last statement in main():
    return 0;
    That tells the operating system that your program ran successfully. If you need to exit the program because an error kept it from running successfully, then return an non-zero value. That is how things work.

    thankx man.... i really appreciate

IMN logo majestic logo threadwatch logo seochat tools logo