标题:帮我看看函数调用数组结构里哪里错了
只看楼主
raymond1010
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-8-9
 问题点数:0 回复次数:4 
帮我看看函数调用数组结构里哪里错了
错误    2    error C2664: “count”: 不能将参数 2 从“month [12]”转换为“const month”    f:\program files\program\study\study\countdays.cpp    41    Study


程序代码:
#include "stdafx.h"
#define STAR "****************************"
/*月份结构*/
const struct month
{
    char *name;
    char sname[4];
    int days;
    int months;
};
/*计算输入月份以及以前的天数*/
int count(int, const struct month);

int main(void)
{
    struct month mymonth[12]=
    {
        {"January","jan",31,1},
        {"Febuary","feb",28,2},
        {"March","mar",31,3},
        {"April","apr",30,4},
        {"May","may",31,5},
        {"June","jun",30,6},
        {"July","jul",31,7},
        {"Auguest","aug",31,8},
        {"Sepetember","sep",30,9},
        {"October","oct",31,10},
        {"November","nov",30,11},
        {"December","dec",31,12}
    };
    int i;

    printf("%s%s",STAR,STAR);
    printf("This program work out the days before(include) the month you entered.");
    printf("%s%s",STAR,STAR);
/*有效性判断*/
    while((scanf("%d",&i)!=1)||((i<1)||(i>12)))
    {
        printf("Please enter a number between 1 and 12, eg.:3. : ");
    }
    printf("The days are:%d",count(i, mymonth));
    return 0;
}

int count(int n, const struct month mon[])
{
    int i,result;
    for(i=0,result=0;i<n;i++)
    {
        result+=mon[i].days;
    }
    return result;
}

搜索更多相关主题的帖子: 函数 结构 March mar feb 
2008-08-14 19:27
raymond1010
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-8-9
得分:0 
没人看吗?
2008-08-14 19:33
raymond1010
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-8-9
得分:0 
解决了,函数声明的时候少了个[]
2008-08-14 19:45
raymond1010
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-8-9
得分:0 
假如输入字符将产生死循环
请问为何啊,我不是限制了条件了嘛?
2008-08-14 19:50
raymond1010
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-8-9
得分:0 
原来是scanf缓冲区的问题,解决了
2008-08-15 22:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-228308-1-1.html




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

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