这是程序。它充分评论了它的目标等。问题有两个:
a) 我在创建函数原型时收到“数据定义没有类型或存储类”的典型错误。
b)输入scanf问题的输入并按回车后,我仍然需要输入任何字母并再次按回车继续执行程序,否则它不会继续:谢谢
#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");
}