Create a structure and access it using pointers to structures in C

#include <stdio.h>
#include <string.h>
 
struct books{
       char title[20];
       char publisher[25];
       char author[20];
       int no_of_pages;
       float cost;
};
int main()
{
   struct books book1,*pb=&book1;
 
   strcpy(pb->title,"C tutorials");
   strcpy((*pb).publisher,"xxxx");
   strcpy(pb->author,"xxxx");
   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);
 
   return 0;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.