Program to illustrate typedef in C

#include <stdio.h>
#include  <string.h>
 
typedef struct {
      char title[20];
      char publisher[25];
      char author[20];
      int no_of_pages;
      float cost;
}  books;
 
int main()
{
   books book1;
 
   strcpy(book1.title,"C tutorials");
   strcpy(book1.publisher,"sdfsdf");
   strcpy(book1.author,"xxxxhjh");
   book1.no_of_pages=281;
   book1.cost=72.00;
   printf("Book Title: %sn",book1.title);
   printf("Book Publisher: %sn",book1.publisher);
   printf("Book Author: %sn",book1.author);
   printf("No. of Pages: %dn",book1.no_of_pages);
   printf("Cost: %fn",book1.cost);
   return 0;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.