Illustrate structure member passing to and from functions in C

#include  <string.h>
 
struct books{
       char title[20];
       char publisher[25];
       char author[20];
       int no_of_pages;
       float cost;
};
 
float modify_cost(float);
 
int main()
{
   struct books book1,*pb=&book1;
 
   strcpy(pb->title,"C tuts");
   strcpy((*pb).publisher,"xxxxxx");
   strcpy(pb->author,"xxxxxxx");
   pb->no_of_pages=281;
   pb->cost=72.00;
   printf("Book Title: %sn",pb->title);
   printf("Book Publisher: %sn",pb->publisher);
   printf("Book Author: %sn",pb->author);
   printf("No. of Pages: %dn",pb->no_of_pages);
   printf("Cost: %fn",pb->cost);
   pb->cost=modify_cost(pb->cost);
   printf("New Cost: %fn",pb->cost);
   return 0;
}
 
float modify_cost(float cost)
{
   struct books temp;
   temp.cost=++cost;
   return temp.cost;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.