Hello friends. here is my situation.
1. I am learning C programming myself with the help of the book C PROGRAMMING ABSOLUTE BEGINNERS GUIDE.
2. I am using code blocks ide compiler.
3. in this book now i am learning SETTING UP DATA WITH STRUCTURES. And I have an example of the STRUCT.
Code:
//header file "bookInfo.h" saved in the same folder
struct bookInfo {
char title[40];
char author[25];
float price;
int pages;
};
Code:
#include "bookInfo.h" // header file already created and saved in the same folder.
#include <stdio.h>
main()
{
int ctr;
struct bookInfo books[3];
for (ctr = 0; ctr < 3; ctr++)
{
printf("What is the name of the books #%d?\n", (ctr+1));
gets(books[ctr].title);
puts("Whos the author? ");
gets(books[ctr].author);
puts("How much did the book cost? ");
scanf(" $%f", &books[ctr].price);
puts("How many pages in the books? ");
scanf(" %d", &books[ctr].pages);
getchar();
}
printf("\n\nHere is the collection of books: \n");
for (ctr = 0; ctr <3; ctr++)
{
printf("#%d: %s by %s", (ctr+1), books[ctr].title, books[ctr].author);
printf("\nIt is %d pages and costs $%.2f", books[ctr].pages, books[ctr].price);
printf("\n\n");
}
return(0);
}
now the prob is when i compile the program
1. it works ok upto
puts("How many pages in the books? ");
after this it does not take any value...just printing on the screen n jumping to new loop n start from 2nd iteration.
i am completely lost here. dont understand what to do here. please HELP.