C Programming
Computer Programming

C program to demonstrate example structure pointer using user define function



Write a program in C to demonstrate example structure pointer (structure with pointer) using user define function

\* C program to demonstrate example structure pointer using user define function *\

# include < stdio.h >
# include < conio.h >
struct   item
{

char itemName[30] ;
int qty ;
float price ;
float amount ;

} ;

void   readItem( struct item *i )
{

printf("\n Enter product name: ") ;
gets(i->itemName ) ;
printf(" Enter price:" ) ;
scanf("%f",&i->price ) ;
printf(" Enter quantity: ") ;
scanf("%d",&i->qty ) ;
i->amount =(float)i->qty * i->price ;

}

void   printItem( struct item *i )
{

printf("\n Name: %s",i->itemName ) ;
printf("\n Price: %f",i->price ) ;
printf("\n Quantity: %d",i->qty ) ;
printf("\n Total Amount: %f",i->amount ) ;

}

int   main( )
{

struct item itm ;
struct item *pItem ;

pItem = &itm ;
readItem( pItem ) ;
printItem( pItem ) ;
return 0 ;

}

Output of Program :

Output of C program to demonstrate example structure pointer using user define function