/* It is not entering data into the third scanf() statement .*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(void)
{
struct book
{
char name;
int pages;
float price;
};
struct book a1,a2,a3,a4;
printf("Enter data into 3 books\n");
scanf("%c %d %f",&a1.name,&a1.pages,&a1.price);
scanf("%c %d %f",&a2.name,&a2.pages,&a2.price);
scanf("%c %d %f",&a3.name,&a3.pages,&a3.price);
printf(" you entered:\n");
printf("\n%c %d %f",a1.name,a1.pages,a1.price);
printf("\n%c %d %f",a2.name,a2.pages,a2.price);
printf("\n%c %d %f",a3.name,a3.pages,a3.price);
getch();
}
/* It is not entering data into the third scanf() statement .*/ #include<stdio.h> #include<conio.h>
Share
you are wanting a string as a name, while you are giving a %c specifier for the input which expects a character.
so either use %s for a string input.
or better use some string function like gets()
And again to remind that you must be careful with size of string(char array) to avoid stack overflows.
Thanks
Alok.Kr.