ever_freedom
feverk
采纳率100%
2015-11-15 05:48

C结构,帮忙看看是什么错啊

已采纳

#include
#define MAXTITL 40
#define MAXAUTL 40
#define MAXBKS 100
struct book {
char title[MAXTITL];
char author[MAXTITL];
float value;
}
int main (void)
{
struct book library[MAXBKS];
int count = 0;
int index;

printf("Please enter the book title.\n");
printf("Press [enter] at the start of a line to stop.\n");
while(count<MAXBKS && gets(library[count].title)!=NULL
                    && library[count].title[0] != '\0')
{
    printf("Now enter the author.\n");
    gets(library[count].author);
    printf("Now enter the value.\n");
    scanf("%f",&library[count].value);
    while(getchar()!='\n')
        continue;
    if(count<MAXBKS)
        printf("Enter the next title.\n");
}
if(count>0)
{
    printf("Here is the list of your books: \n");
    for(index=0;index<count;index++)
    printf("%s by %s: $%.2f\n",library[index].title,
                library[index].author,library[index].value);
}
else
    printf("No books?Too bad.\n");
return 0;

}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • Meditator_hkx Meditator_hkx 6年前
     struct book {
    char title[MAXTITL];
    char author[MAXTITL];
    float value;
    } ;   //你原来的代码这里少了一个;
    
    点赞 2 评论 复制链接分享
  • apprentices apprentices 6年前

    #define _CRT_SECURE_NO_WARNINGS
    #include
    #define MAXTITL 40
    #define MAXAUTL 40
    #define MAXBKS 100
    struct book
    {
    char title[MAXTITL];
    char author[MAXTITL];
    float value;
    };
    int main()
    {
    struct book library[MAXBKS];
    int count = 0;
    int index;
    printf("Please enter the book title.\n");
    printf("Press [enter] at the start of a line to stop.\n");
    while (count && library[count].title[0] != '\0')
    {
    printf("Now enter the author.\n");
    gets(library[count].author);
    printf("Now enter the value.\n");
    scanf("%f", &library[count].value);
    while (getchar() != '\n')
    continue;
    if (count printf("Enter the next title.\n");
    }
    if (count>0)
    {
    printf("Here is the list of your books: \n");
    for (index = 0; index<count; index++)
    printf("%s by %s: $%.2f\n", library[index].title,library[index].author, library[index].value);
    }
    else
    printf("No books?Too bad.\n");
    //system("pause");
    return 0;
    }

    点赞 评论 复制链接分享
  • IOSfengguibin IOSfengguibin 6年前

    报的什么错? 你先把错误发出来

    点赞 评论 复制链接分享

相关推荐