Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C
include<stdio.h>
 struct book;
 { 
char Name[30];
 char Authors[30] ; 
int ISBN code[30]; 
float Price; 
} 
int main() 
{
struct book b; 
printf(" Enter the book name:"); fgets(b.book_name, 30, stdin);
 printf("Enter the author name:\n");
fgets(b.author, 30, stdin); 
printf("Enter the ISBN code\n:"); 
scanf("%d", &b.book_code); 
printf("Enter the Price:"); 
scanf("%f", &b.Price); 
printf("The Details of the book is:\n\n"); printf("Book name is:\n"); 
printf("Author name is:\n"); 
printf("ISBN code is:%d\n", b.book_code); printf("book Price is: %0.2f\n", b.Price); 
return 0;
 }


What I have tried:

Storage size of 'b' isn't known
Struct book b;
expected identifier or '(' before '{' token
{
^
Posted
Updated 29-Dec-22 5:05am
v3

This is a second attempt at your previous question, and you still have some very basic errors.
C++
#include<stdio.h> // include statements must start with the '#' character
struct book       // do not put a semi-colon on this line
{ 
    char Name[30];
    char Authors[30] ; 
    int ISBNcode[30]; // ISBN and code need to be one word. And are you sure you want an array of int types?
    float Price; 
}; // do put a semi-colon on this line
int main() 
{
    struct book b; 
    
    printf(" Enter the book name:"); 
    fgets(b.book_name, 30, stdin); // in this and the following lines you are not using the correct field names
    printf("Enter the author name:\n");
    fgets(b.author, 30, stdin); 
    printf("Enter the ISBN code\n:"); 
    scanf("%d", &b.book_code); // this is not valid as ISBNcode is an array
    printf("Enter the Price:"); 
    scanf("%f", &b.Price); 
    printf("The Details of the book is:\n\n"); // 
    printf("Book name is:\n");                 // these statements are incomplete
    printf("Author name is:\n");               //
    printf("ISBN code is:%d\n", b.book_code); 
    printf("book Price is: %0.2f\n", b.Price); 
    return 0;
}
 
Share this answer
 
v3
Comments
Richard MacCutchan 29-Dec-22 11:35am    
Look again at my suggestions above.
Richard MacCutchan 29-Dec-22 12:38pm    
I have a better idea. Get a book or read your study notes and try to do the work yourself. You will learn much faster by actually trying to correct your own basic errors.
Rick York 29-Dec-22 22:14pm    
Why should anyone do YOUR work for you?
I've already told you: C doesn't like a casual approach to its syntax, you must be exact. Try:
C
#include <stdio.h>
struct book
{
  char Name[30];
  char Author[30] ;
  char Isbn[30];
  float Price;
};

int main()
{
  struct book b;
  printf(" Enter the book name:"); fgets(b.Name, 30, stdin);
  printf("Enter the author name:\n");
  fgets(b.Author, 30, stdin);
  printf("Enter the ISBN code\n:");
  fgets(b.Isbn, 30, stdin);
  printf("Enter the Price:");
  scanf("%f", &b.Price);
  printf("The Details of the book is:\n\n"); printf("Book name is %s:", b.Name);
  printf("Author name is:%s", b.Author);
  printf("ISBN code is:%s", b.Isbn); printf("book Price is: %0.2f\n", b.Price);
  return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900