Click here to Skip to main content
15,392,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include<stdio.h>
typedef struct employee;
{         // error [ expecter identifier or'(' ]
    int empid;
    char empname[30];
    long salary;
}EMP;
void main()
{
    void E1,E2,E3;     //error [ varaiable has incomplete type 'void' ]
    EMP; E1;E2;E3;
   // printf("%lu",sizeof(E1));
    printf("Enter Employee Id");
    scanf("%d",&E1.empid);
    
    printf("Enter Employee name: ");
    gets(E2.empid);
    
    printf("Enter Employee Salary");
    scanf("%d",&E3.empid);
}


What I have tried:

I have tried my best as a beginner
Posted
Updated 10-Feb-22 4:12am

C++
EMP; E1;E2;E3;

You cannot declare variables as void types. The compiler has no way of telling what data you expect them to contain.

And the following line does not mean anything.
C++
EMP; E1;E2;E3;

If you want to declare three variables of type EMP you need something like:
C++
EMP E1, E2, E3;

But you should not be putting one part of the class into each variable. The correct code would be:
C++
    EMP  E1;
   // printf("%lu",sizeof(E1));
    printf("Enter Employee Id");
    scanf("%d",&E1.empid);
    
    printf("Enter Employee name: ");
    gets(E1.empname); // use empname here
    
    printf("Enter Employee Salary");
    scanf("%ld",&E1.salary); // 'ld' for long value, and salary for the variable name

// You now need some code here to process the employee entry.
   
Comments
Aditya Soni 2022 10-Feb-22 10:00am
   
Thnx , It helped me
CPallini 10-Feb-22 10:12am
   
5.
In addition to Richards comments:
C
typedef struct employee;
{         // error [ expecter identifier or'(' ]
    int empid;
    char empname[30];
    long salary;
}EMP;
Remove the semicolon: it terminates the typedef definition.
C
typedef struct employee
{         
    int empid;
    char empname[30];
    long salary;
}EMP;
   
Comments
Richard MacCutchan 10-Feb-22 10:36am
   
Yeah, I forgot about the first semi-colon.
A working (albeit not robust) version of your code:
C
#include<stdio.h>
  
typedef struct employee
{
    int id;
    char name[30];
    long salary;
} EMP;

int main()
{
  EMP employee;

  printf("size of the EMP struct: %lu\n",sizeof(employee));

  printf("Enter Employee Id: ");
  scanf("%d", &employee.id);

  printf("Enter Employee Name: ");
  scanf("%s",employee.name);

  printf("Enter Employee Salary: ");
  scanf("%ld",&employee.salary);

  printf("Employee { id = %d, name = %s, salary = %ld}\n", employee.id, employee.name, employee.salary);

  return 0;
}
   
Comments
Richard MacCutchan 10-Feb-22 10:36am
   
+5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900