これがプログラムです。目的などについて完全にコメントされています。問題は2つあります。
a) 関数のプロトタイプを作成するときに、「データ定義に型またはストレージ クラスがありません。
b) scanf の質問に入力して Enter キーを押した後、文字を入力してもう一度 Enter キーを押してプログラムを続行する必要があります。それ以外の場合は進行しません: ありがとう
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
/* Object:
* A program that allows upon user input recreate structures
* with different names. Except when entering 'n', it will always
* ask "Do you want to create a new book (structure)?
* It is about storing books, title, author, price, and pages */
// 1. I create the blue print of the structure (forget about typedef...)
struct book {
char title[100];
int pages;
int price;
char author[50];
} ;
// 2. I declare some variables
char wants;
char name [30];
// 3. Function prototypes
question();
create_structure_name();
// +++++++++++++++++++++++++++++++++++++++++++++++++++
create_structure_name(){
printf("Give a name to your structure: ");
fflush(stdin);
scanf("%s\n", &name);
printf("you have chosen this name %s for the structure: \n", name);
struct book name;
printf("Title: ");
fflush(stdin);
scanf("%s\n", &name.title);
printf("The title is %s: ", name.title);
printf("Paginas: ");
fflush(stdin);
scanf("%d\n", &name.pages);
printf("It has this number of pages %d\n: ", name.pages);
printf("Price: ");
fflush(stdin);
scanf("%d\n", &name.price);
printf("The price is %d: ", name.price);
printf("Author: ");
fflush(stdin);
scanf("%s\n", &name.author);
printf("The author is %s: ", name.author);
}
// I define the function ++++++++++++++++++++++++++++
question()
{
printf("Do you want to create a new book? :");
fflush(stdin);
scanf("%c\n", &wants);
while(wants!= 'n')
{
create_structure_name();
}
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++
main(void)
{
create_structure_name();
question();
system("PAUSE");
}