Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

simple program in c for employee record

i m facing problem while getting input ..scanf,gets,getline nothing is goin properly....and also i cannot enter my name




#include

typedef struct employee
{
char name[30];
char address[30];
int academics;
char sex[10];
int experience;
char dob[30];
char extra[20];
char other[20];
}EMP;

EMP emp[30];
int main()
{

int n,i;

printf("
EMPLOYEE DETAILS
");
for(i=0;i<2;i++)
{
printf("Enter your name:
");
getline(emp[i].name,30);
printf("Enter your address:
");
gets(emp[i].address);
printf("Enter your academics marks:
");
gets(&emp[i].academics);
printf("Enter your sex:
");
gets(emp[i].sex);
printf("Enter how may years of experience you have:
");
gets(&emp[i].experience);
printf("Enter your date of birth:
");
gets(emp[i].dob);
printf("Enter your extra curicullam activities:
");
scanf("%c",emp[i].extra);
printf("Enter other if any :
");
scanf("%s",emp[i].other);
}
printf("
Employee details are :
");
for(i=0;i<2;i++)
{
printf("Name:%s
",emp[i].name);
printf("Address:%s
",emp[i].address);
printf("Academics marks:%d
",emp[i].academics);
printf("Sex:%s
",emp[i].sex);
printf("Experience:%d
",emp[i].experience);
printf("Date of Birth:%d
",emp[i].dob);
printf("Extra activities:%s
",emp[i].extra);
printf("Others:%s
",emp[i].other);
printf("******************End of Details******************
");
}
return(0);
}

Comments

  • anthrax11anthrax11 Posts: 511Member
    3 things:

    1) This is the Assembly forum, you're looking for the [link=http://www.programmersheaven.com/mb/candcpp/board.aspx]C/C++ forum[/link]

    2) When posting code, use code tags:
    [leftbr]code[rightbr]
    // code here
    [leftbr]/code[rightbr]

    3) Don't use gets, you can't give it the size of the buffer so your buffer might overflow. Also, gets only receives strings, not integers.
    [code]
    #include

    typedef struct employee
    {
    char name[30];
    char address[30];
    int academics;
    char sex[10];
    int experience;
    char dob[30];
    char extra[20];
    char other[20];
    }EMP;

    EMP emp[30];
    int main()
    {

    int n,i;

    printf("
    EMPLOYEE DETAILS
    ");
    for(i=0;i<2;i++)
    {
    printf("Enter your name:
    ");
    [color=Red]scanf("%29s", &emp[i].name);[/color]
    printf("Enter your address:
    ");
    [color=Red]scanf("%29s", &emp[i].address);[/color]
    printf("Enter your academics marks:
    ");
    [color=Red]scanf("%d", &emp[i].academics);[/color]
    printf("Enter your sex:
    ");
    [color=Red]scanf("%9s", &emp[i].sex);[/color]
    printf("Enter how may years of experience you have:
    ");
    [color=Red]scanf("%d", &emp[i].experience);[/color]
    printf("Enter your date of birth:
    ");
    [color=Red]scanf("%29s", &emp[i].dob);[/color]
    printf("Enter your extra curicullam activities:
    ");
    scanf("%19s", &emp[i].extra);
    printf("Enter other if any :
    ");
    scanf("%19s", &emp[i].other);
    }
    printf("
    Employee details are :
    ");
    for(i=0;i<2;i++)
    {
    printf("Name:%s
    ",emp[i].name);
    printf("Address:%s
    ",emp[i].address);
    printf("Academics marks:%d
    ",emp[i].academics);
    printf("Sex:%s
    ",emp[i].sex);
    printf("Experience:%d
    ",emp[i].experience);
    printf("Date of Birth:[color=Red]%s[/color]
    ",emp[i].dob);
    printf("Extra activities:%s
    ",emp[i].extra);
    printf("Others:%s
    ",emp[i].other);
    printf("******************End of Details******************
    ");
    }
    return(0);
    }
    [/code]
Sign In or Register to comment.