0

The code is not printing for name and salary of employee, also not asking for the salary of the employee, kindly mark the wrong items in the code.

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

struct employee{
    int code;
    char name[20];
    int salary;
};

void printEmployeeDetails(struct employee emp);

void printEmployeeDetails(struct employee emp){
    printf("Employee CODE is: %d\n" ,emp.code);
    printf("Employee NAME is: %s\n" ,emp.name);
    printf("Employee SALARy is: %d\n",emp.salary);     

}

int main(){
    struct employee e1;
    printf("Enter your CODE\n");
    scanf("%d",&e1.code);

    printf("Enter your NAME\n");
    scanf("%d",&e1.name);

    printf("Enter your SALARY\n");
    scanf("%d",&e1.salary);

    printEmployeeDetails(e1);

    //printf("The Employee Details Are: \n",printEmployeeDetails(e1));
    return 0;
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Prerna
  • 17
  • 3

1 Answers1

2

I take that this is a C++ question. You might have turned off compiler warning when compile; as from the compiler warnings (I used onlinegdb compiler), there are a couple issues with your code

First

printf("Enter your NAME\n");
scanf("%d",&e1.name);

You are expecting e1.name to be a string here, so use "%s" instead of "%d"

Seconly, when using scanf for a char* variable, you only need to use scanf("%s", e1.name) (no need for the &)

For more details, read here: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)’

Final

printf("Enter your NAME\n");
scanf("%s",e1.name);
Bao Huynh Lam
  • 974
  • 4
  • 12