I wrote this code that takes user input and then prints it out, but it's not working properly. It only recieves the name but not the age or salary of worker.
#include <stdio.h>
#include <stdlib.h>
struct worker
{
char sri[100];
int age;
double salary;
};
int main()
{
struct worker *ptr;
int n;
printf("enter number of employy ");
scanf("%d", &n);
//allocating memory for n ;
ptr = (struct worker *)malloc(n * sizeof(struct worker));
for (int i = 0; i < n; ++i)
{
printf("For employee: %d \n ", i+1);
printf("Enter your name : ");
scanf("%s\n", (ptr + i)->sri);
printf("Enter salary:\n ");
scanf("%lf \n", (ptr + i)->salary);
printf("Enter age : \n");
scanf("%d \n", (ptr + i)->age);
}
for (int i = 0; i < n; ++i)
{
printf("Employee %d: ", i+1);
printf("name =%s ", (ptr + i)->sri);
printf("age = %d, ", (ptr + i)->age);
printf("salary = %.2lf\n", (ptr + i)->salary);
}
free(ptr);
return 0;
}