#include<stdio.h>
#include<string.h>
struct employee
{
int id;
char name[20];
float salary;
char addr[];
}*emp;
void get_emp(struct employee **record)
{
printf("\tplease enter details of employee:\n");
printf("id= ");
scanf("%d",(*record)->id);//code to get input value
printf("Name= ");
scanf(" %s",(*record)->name);
printf("salary= ");
scanf("%f",(*record)->salary);
}
int main()
{
get_emp(&emp);
printf("id=%d\n",emp->id); // code to display the value
printf("Name=%s\n",emp->name);
printf("salary=%f\n",emp->salary);
return 0;
}
I have a structure example and I want to pass structure pointer to the function without using normal variable but only pointer. Is the parameter(double pointer) in the function get_emp(struct employee **record) a correct way to do if not what changes should be made? Also how to get input value from users in the function get_emp(struct employee **record) and how to display the value?
empis initialized to NULL (static storage), and it's a pointer. You're not allocating the memory for the struct anywhere, so(*record)->idis like writing(NULL)->id, which is of course wrong