structure for books using arrays

/* there is an issue in the program...while trying to enter the name of the book 2nd time, just after entering price of 1st book...it is jumping to next data*/  
#include <stdio.h>
void main()
{   int i;
    struct book
    {
        int nop;
        char name;
        float price;
    }b[2];
    for(i=0;i<2;i++)
    {
         printf("\n enter name of book %d :",i+1);
    scanf("%c",&b[i].name);
      printf("\n enter no of pages of book %d :",i+1);
    scanf("%d",&b[i].nop);
    printf("\n enter PRICE of book %d :",i+1);
    scanf("%f",&b[i].price);
    printf("-------------");
     
    }
    for(i=0;i<2;i++)
    {
    printf("\n  name of the book:%c",b[i].name);
    printf("\n  no of pages:%d",b[i].nop);
     printf("\n price:%f",b[i].price);
     }
}

తెరమీద 
/tmp/kMZkH5pbco.o
enter name of book 1 :z
enter no of pages of book 1 :205
enter PRICE of book 1 :30.75
-------------
 enter name of book 2 :
 enter no of pages of book 2 :308
 enter PRICE of book 2 :25.25
 -------------
  name of the book:z
  no of pages:205
 price:30.750000
  name of the book:

  no of pages:308
 price:25.250000

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)