| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1098 人关注过本帖
标题:一段小程序,有点问题,不知道怎么解决,大家都来看看
取消只看楼主 加入收藏
蹴鞠者
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:82
专家分:134
注 册:2016-9-26
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:2 
一段小程序,有点问题,不知道怎么解决,大家都来看看
程序代码:
#include<stdio.h>
#define TITL 40
#define AUTL 40
#define BKS 2
struct book {
    char title[TITL];
    char author[AUTL];
    float value;
};

int main()
{
    struct book library[BKS];
    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 < BKS && gets(library[BKS].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');  
        if(count < BKS)
            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;



}
搜索更多相关主题的帖子: count 
2017-06-06 16:13
蹴鞠者
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:82
专家分:134
注 册:2016-9-26
收藏
得分:0 
我运行之后,library[count].title[0] != '\0'没起作用。。。。而且library[index].title输出也不对,看了半天不知道是什么问题

[此贴子已经被作者于2017-6-6 16:16编辑过]

2017-06-06 16:14
蹴鞠者
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:82
专家分:134
注 册:2016-9-26
收藏
得分:0 
大家来看看是什么问题

[此贴子已经被作者于2017-6-6 16:17编辑过]

2017-06-06 16:15
快速回复:一段小程序,有点问题,不知道怎么解决,大家都来看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011829 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved