【解決方法】 ‘b’ のストレージ サイズが既知の構造体ブックではありません。 ‘{‘ トークンの前に識別子または ‘(‘ が必要です

プログラミングQA


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;
 }

私が試したこと:

‘b’ のストレージ サイズが不明です
ブック b を構造化します。
「{」トークンの前に識別子または「(」が必要です
{
^

解決策 1

私はすでにあなたに言った: C その構文へのカジュアルなアプローチは好きではありません。正確でなければなりません。 試す:

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;
}

解決策 2

これはあなたの前の質問に対する 2 回目の試みであり、まだいくつかの非常に基本的なエラーがあります。

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;
}

コメント

タイトルとURLをコピーしました