Hi, I am prati. New to this forum.I have written one C programme for structure. In this programme i passing pointer of the array of structure to the display function.
It takes the input from the user but i am not getting proper output.I mean its display loop is not working.Please help to solve this problem.
#include<stdio.h>
#include<conio.h>
struct data{
int ID;
char name[4];
};
typedef struct data record;
void display(record *[]);
record emp[2];
int i;
void main()
{
record *ptr[2];
ptr=&emp[0];
clrscr();
for(i=0;i<2;i++)
{
printf("enter name");
scanf("%s",&emp.name);
printf("enter ID");
scanf("%d",&emp.ID);
}
display(ptr);
}
void display(record *ptr[])
{
for(i=0;i<2;i++)
{
printf("%s %d",ptr->name,ptr->ID);
}
getch();
}
It takes the input from the user but i am not getting proper output.I mean its display loop is not working.Please help to solve this problem.
#include<stdio.h>
#include<conio.h>
struct data{
int ID;
char name[4];
};
typedef struct data record;
void display(record *[]);
record emp[2];
int i;
void main()
{
record *ptr[2];
ptr=&emp[0];
clrscr();
for(i=0;i<2;i++)
{
printf("enter name");
scanf("%s",&emp.name);
printf("enter ID");
scanf("%d",&emp.ID);
}
display(ptr);
}
void display(record *ptr[])
{
for(i=0;i<2;i++)
{
printf("%s %d",ptr->name,ptr->ID);
}
getch();
}