Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: structure

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Malaysia
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    structure

    Dear sir,

    That is occurs error on my C program structure.

    #include <stdio.h>
    struct student_type
    {
    char first_name[20];
    char family_name[20];
    int student_id;
    };
    main()
    {
    struct student_type undergraduate;
    printf(“Enter first name :”);
    gets(undergraduate.first_name);
    printf(“Enter family name :”);
    gets(undergraduate.family_name);
    printf(“Enter student id name :”);
    gets(undergraduate.student_id);
    printf(“%s %s, id number %d \n”, undergraduate.first_name,
    undergraduate.family_name,
    undergraduate.student_id,
    return 0; }

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You shouldn't be using gets to get an integer. Use scanf instead.

    scanf("%d",&(undergraduate.student_id));

    and although I believe that main() works, it is much nicer to say int main(void)

    And you forgot to put the ending parenthesis on your last printf. Get rid of that last comma and put );
    Last edited by Josh Campbell; 12-23-2002 at 03:13 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •