问答详情
源自:4-17 switch与if语句的应用

关于if...else语句,发现 if 的 花括号包含了else及其花括号 ,然后直接修改,蹦出了以下错误及警告,想请教一下大佬为什么会产生这种情况。

hello.c: In function 'main':
hello.c:57:74: error: stray '\357' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                          ^
hello.c:57:75: error: stray '\274' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                           ^
hello.c:57:76: error: stray '\214' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                            ^
hello.c:57:77: error: expected ')' before 'year'
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                             ^~~~
hello.c:57:22: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                      ^
hello.c:57:27: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                           ^
hello.c:57:32: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                ^
hello.c:57:67: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                   ^
hello.c:62:74: error: stray '\357' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                          ^
hello.c:62:75: error: stray '\274' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                           ^
hello.c:62:76: error: stray '\214' in program
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                            ^
hello.c:62:77: error: expected ')' before 'year'
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                             ^~~~
hello.c:62:22: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                      ^
hello.c:62:27: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                           ^
hello.c:62:32: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                ^
hello.c:62:67: warning: format '%d' expects a matching 'int' argument [-Wformat=]
             printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);
                                                                   ^


提问者:importerror 2018-10-06 19:07

个回答

  • importerror
    2018-10-06 19:17:26

    原代码:

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

            {

                sum =sum + 1 + day;

                printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum);

            ②

                else

                {

                    sum =sum + day;   

                    printf("%d年%d月%d日这一天,是该年中的第%d天\n",year,month,day,sum); 

                }

            }①

    直接把①移到了②,然后报错,想知道原因