source file name: structptr.C
#include<string.h>
#include <stdio.h>
struct Person
{
char *name;
char *address;
int age;
};
int main()
{
void voterlist(struct Person *ptr);
int i,n;
struct Person p[]={
{"Sachin Patil","Chiplun",25},{"Shetal Pawar","Latur",15},
{"Mohan Joshi","Satara",56},{"Soham Kadam","Mumbai",20},
{"Harish Mane","Poona",45},{"Ram Gopal","Gujarat",16}};
//clrscr();
printf("\n Person list: ");
for(i=0;i<6;i++)
{
printf("\n %s\t%s\t%d ",p[i].name,p[i].address,p[i].age);
}
voterlist(&p[0]);
//getch();
return 0;
}
void voterlist(struct Person *ptr)
{
int i;
int vt;
int cnt=0;
printf("\n Eligible Voters : ");
for(i=1;i<=6;i++)
{
vt=ptr->age;
if(vt>18)
{
cnt++;
printf("\n %s\t%s ",ptr->name,ptr->address);
}
ptr++;
}
printf("\n counter: %d", cnt);
}
output:
0 Comments
Post a Comment