technoPhobe9312
Contributor
Code:
[URL="http://www.techenclave.com/usertag.php?do=list&action=hash&hash=include"]#include[/URL] <stdio.h>
[URL="http://www.techenclave.com/usertag.php?do=list&action=hash&hash=include"]#include[/URL] <conio.h>
void main()
{
char name[3];
float price[3];
int pages[3],i;
clrscr();
printf("Enter names,prices and no. of pages of 3 books\n");
for(i=0;i<=2;i++)
scanf("%c %f %d",&name[i],&price[i],&pages[i]);
printf("\n\nAnd this is what you entered\n");
for(i=0;i<=2;i++)
printf("%c %f %d\n",name[i],price[i],pages[i]);
getch();
}
________
above i have written a code for storing the details of a book
from a c language book
but when i try to enter the details of the second book it does not take it and shows some garbage value
what can be the issue
my compiler is turbo C++ IDE
- - - Updated - - -
this structure approach is not working well as well same issue
#include<stdio.h>
#include<conio.h>
void main()
{
struct book
{
char name;
float price;
int pages;
};
struct book b1,b2,b3;
clrscr();
printf("enter the name,price nad pages of 3 books\n");
scanf("%c%f%d",&b1.name,&b1.price,&b1.pages);
scanf("%c%f%d",&b2.name,&b2.price,&b2.pages);
scanf("%c%f%d",&b3.name,&b3.price,&b3.pages);
printf("and this is what you entered");
printf("%c %f %d",b1.name,b1.price,b1.pages);
printf("%c %f %d",b2.name,b2.price,b2.pages);
printf("%c %f %d",b3.name,b3.price,b3.pages);
getch();
}
________________________________________________