gpt4 book ai didi

c - 错误 : too few arguments to function `printDay' (C language)

转载 作者:太空宇宙 更新时间:2023-11-04 05:51:16 26 4
gpt4 key购买 nike

问题

我是 C 的新手,尝试编译它 (GCC) 时出现此错误:

error: too few arguments to function `printDay'

我的问题是:

  1. 这是什么意思?
  2. 我该如何解决这个问题?

P.S 这不是我的完整代码,这只是我遇到的这个错误。提前致谢。

代码

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>

#define MAX_DAYS 31
#define MIN_DAYS 1
#define MAX_MONTHS 12
#define MIN_MONTHS 1

enum monthsOfYear
{
jan = 1,
feb,
mar,
apr,
may,
jun,
jul,
aug,
sep,
oct,
nov,
dec
};

enum daysOfWeek
{
sun = 1,
mon,
tue,
wed,
thu,
fri,
sat
};

int input();
void check(int month, int day);
void printDay(int month, int day, int firstDay);

int main()
{
printf("Hello! Welcome to the day calculator!\n");
printDay(input());
return (0);
}

/*this function takes the input from the user
input: none
output: the first day
*/
int input()
{
enum daysOfWeek day = 0;
enum monthsOfYear month = 0;

int firstDay = 0;

printf("Enter month to check: (1-jan, 2-feb, etc) ");
scanf("%d", &month);
printf("Enter day to check: ");
scanf("%d", &day);
check(month,day);
printf("Enter the weekday of the 1st of the month: (1-Sunday, 2-Monday, etc) ");
scanf("%d", &firstDay);

return firstDay;
}

/*
this function checks the validity of the input
input: day, month
output: none
*/
void check(int month, int day)
{
if(month > MAX_MONTHS || month < MIN_MONTHS && day > MAX_DAYS || day < MIN_DAYS)
{
printf("Invalid input, try again\n");
input();
}
if (month == feb && day > 28)
{
printf("Invalid input, try again\n");
input();
}
if (month == jan && day > 31)
{
printf("Invalid input, try again\n");
input();
}
}

void printDay(int month, int day, int firstDay)
{
int date = 0;
date = day - firstDay;
switch(day)
{
case sun:
printf("%d.%d will be a Sunday", day, month);
break;

default:
break;
}
}

最佳答案

  1. What does it mean?

error: too few arguments to function 'printDay'” 表示您在此处调用 printDay 时传递了错误数量的参数:

printDay(input());

您正在传递一个参数,但您对 printDay 的声明显示它需要 3 个参数:

void printDay(int month, int day, int firstDay);
  1. How do I fix this?

您可以通过传递正确数量的参数来修复它,例如:

int month = ...;
int day = ...;
int firstDay = ...;
printDay(month, day, firstDay);

关于c - 错误 : too few arguments to function `printDay' (C language),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41365499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com