Program 56) Write a program to illustrate the use of structure pointers.
A program to illustrate the use of a structure pointer to manipulate the elements of an array of structures. Note that the pointer ptr (of type struct invent) is also used as the loop control index in four loops.
PROGRAM
struct invent
{
char *name [20] ;
int number ;
float price ;
} ;
main ( )
{
struct invent product [3], *ptr ;
printf(" INPUT \n\n) ;
for (ptr = product ; ptr < product + 3 ; ptr+)
scanf ("%s %d %f ", ptr->name, &ptr->number,
&ptr->price) ;
printf ("\nOUTPUT\n\n") ;
ptr = product ;
while (ptr < product + 3)
{
printf ("%-20s %5d %10.2f\n",
ptr->name,
ptr->number,
ptr->number) ;
ptr++ ;
}
}
Output: INPUT
Washing_machine 5 7500
Electric_iron 12 350
Two_in_one 7 1250
OUTPUT
Washing machine 5 7500.00
Elestric_iron 12 350.00
Two_in_one 7 1250.00
No comments:
Post a Comment