为什么我定义的功能似乎无法运行 [英] Why it seems that the function I defined can't run

查看:77
本文介绍了为什么我定义的功能似乎无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时,我无法输入任何内容,并且程序只是结束并什么也不返回,尽管在我的代码中我想输入和输出某些内容.然后我尝试调试,在我定义的函数中设置了许多关键点,但直接转到代码的末尾.我定义的函数似乎无法运行.我对此感到困惑.你能告诉我出什么事了吗?先感谢您.

When run, I cannot input anything and the program just end and return nothing, though in my code I want to input and output something. And then I tried to debug, I set a lot of key points in the function that I defined, but it directly goes to the end of the code. It seems that the function I defined can't be run. I am confused about that. Could you tell me what was wrong? Thank you in advance.

#include<stdio.h>
void day_of_year();
int main() {

    day_of_year;
    return 0;
}
void day_of_year()

{
    int year; int month; int day;

    scanf_s("%d %d %d", &year, &month, &day);
    int day_tab[2][13] = {

    {0,31,28,31,30,31,30,31,31,30,31,30,31},

    {0,31,29,31,30,31,30,31,31,30,31,30,31} };

    int flag, j;

    flag = (year % 400 == 0) || ((year % 100 != 0) && (year % 4) == 0);

    for (j = 1; j < month; j++)  day += day_tab[flag][j];
    printf("%d", day);
}

推荐答案

要调用该函数,您的语句应显示为day_of_year();,并带有括号.

To call the function, your statement should read day_of_year();, with the parentheses.

day_of_year;是不带括号的表达式,它评估函数的地址,然后对该函数不执行任何操作.

Without the parentheses, day_of_year; is an expression that evaluates the address of the function, then doesn't do anything with it.

这篇关于为什么我定义的功能似乎无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆