This is a program to store employee details and access them using pointer variables. The output is getting displayed but after printing the details the .exe
file crashes.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Emp
{
char name[30];
int id;
char gender[10],mobno[12];
};
int main()
{
struct Emp *p;
p=(struct Emp*)malloc(sizeof(struct Emp*));
printf("\nEnter the employee name : ");
scanf("%s",&p->name);
printf("Enter the employee id : ");
scanf("%d",&p->id);
printf("Enter your gender : ");
scanf("%s",&p->gender);
printf("Enter employee number : ");
scanf("%s",&p->mobno);
printf("\nEmployee details:-\nEmployee id : %d\nEmployee name :: %s\nEmployee's Gender : %s\nEmployee's Mobile number : %s\n ",p->id,p->name,p->gender,p->mobno);
free(p);
return 0;
}
After displaying the output, the .exe
file stops working. Could you help me?