C语言编写小熊时钟,fatal error C1017: 无效的整数常量表达式

用这个代码运行不出结果,错误如下,该怎么解决

img

#include
#include
#include
#include
#include 
#include 
#include 

#define PI 3.1415926
#define ESC 0x011b
int s0 = -1, m0 = -1, h0 = -1;
int main()
{
    int key, i = 3;
    char H[10];
    float n;
    HDC hdc = GetDC(GetConsoleWindow());
    HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 225));
    SelectObject(hdc, hpen);
    Ellipse(hdc, 380, 150, 430, 200);
    Ellipse(hdc, 210, 150, 260, 200);
    Ellipse(hdc, 295, 225, 345, 275);
    Ellipse(hdc, 297, 227, 343, 273);
    for (n = 0; n <= 2 * PI; n += PI / 30)
    {
        MoveToEx(hdc, 320, 240, NULL);
        LineTo(hdc, 320 + 80 * cos(-n), 240 + 80 * sin(-n));
    }
    for (n = 0; n <= 2 * PI; n += PI / 6)
    {
        itoa(i, H, 10);
        TextOutA(hdc, 317 + 73 * cos(-n), 237 + 73 * sin(-n), H, strlen(H));
        i--;
        if (i < 1)
            i += 12;
    }
    while (!kbhit())
    {
        timer();
        Sleep(1000);
    }
    key = getch();
    if (key == ESC)
    {
        ReleaseDC(GetConsoleWindow(), hdc);
        exit(0);
    }
    return 0;
}
void timer()
{
    struct tm* when;
    float s, m1, h1;
    int h, m;
    time_t now;
    time(&now);
    when = localtime(&now);
    h = when->tm_hour;
    m = when->tm_min;
    s = when->tm_sec;
    h1 = (h + (m * 60 + s) / 3600) * PI / 6 - PI / 2;
    m1 = (m + s / 60) * (PI / 30) - PI / 2;
    if (s0 != (-1) && m0 != (-1) && h0 != (-1))
    {
        setcolor(0);
        line(320, 240, 320 + 45 * cos(h0), 240 + 45 * sin(h0));
        line(320, 240, 320 + 55 * cos(m0), 240 + 55 * sin(m0));
        line(320, 240, 320 + 65 * cos(s0), 240 + 65 * sin(s0));
    }
    setcolor(15);
    line(320, 240, 320 + 45 * cos(h1), 240 + 45 * sin(h1));
    line(320, 240, 320 + 55 * cos(m1), 240 + 55 * sin(m1));
    setcolor(4);
    line(320, 240, 320 + 65 * cos(s * (PI / 30) - PI / 2), 240 + 65 * sin(s * (PI / 30) - PI / 2));
    s0 = s * (PI / 30) - PI / 2;
    m0 = m1;
    h0 = h1;
}

#if后面缺个(

修改了下你的,你的代码API和easyx混用,改成纯eaxyx了。

#include <math.h>
#include <time.h>
#include <conio.h>
#include <graphics.h>

void timer();

#define PI 3.1415926
#define ESC 0x011b
int s0 = -1, m0 = -1, h0 = -1;
int main()
{
    int key, i = 3;
    char H[10];
    float n;
    initgraph(640, 480); //

    //  HWND hwnd = GetConsoleWindow(); //
    // HDC hdc = GetDC(GetConsoleWindow());
    // HDC hdc = GetDC(hwnd); //
    // HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 225));

    // SelectObject(hdc, hpen);

    setbkcolor(BLACK);                  // 背景颜色
    setbkmode(TRANSPARENT);              // 文字背景透明
    settextcolor(RGB(255, 255, 255)); // 文字颜色

    while (1) // while (!kbhit())
    {
        setcolor(WHITE);
        fillellipse(380, 150, 430, 200);
        fillellipse(210, 150, 260, 200);
        fillellipse(295, 225, 345, 275);
        fillellipse(297, 227, 343, 273);

        setcolor(RGB(0, 0, 225));
        for (n = 0; n <= 2 * PI; n += PI / 30)
        {
            // MoveToEx(hdc, 320, 240, NULL);
            line(320, 240, 320 + 80 * cos(-n), 240 + 80 * sin(-n)); //        LineTo(hdc, 320 + 80 * cos(-n), 240 + 80 * sin(-n));
        }

        setcolor(WHITE);
        for (n = 0; n <= 2 * PI; n += PI / 6)
        {
            itoa(i, H, 10);
            outtextxy(317 + 73 * cos(-n), 237 + 73 * sin(-n), H); //        TextOut(hdc, 317 + 73 * cos(-n), 237 + 73 * sin(-n), H, strlen(H));
            i--;
            if (i < 1)
                i += 12;
        }

        timer();
        Sleep(1000);
        cleardevice(); // 刷新

        i = 3;
        if (kbhit())
        {
            key = getch();
            if (key == ESC)
            {
                closegraph();
                // ReleaseDC(GetConsoleWindow(), hdc);
                // exit(0);
            }
        }
    }

    return 0;
}
void timer()
{
    struct tm *when;
    float s, m1, h1;
    int h, m;
    time_t now;
    time(&now);
    when = localtime(&now);
    h = when->tm_hour;
    m = when->tm_min;
    s = when->tm_sec;
    h1 = (h + (m * 60 + s) / 3600) * PI / 6 - PI / 2;
    m1 = (m + s / 60) * (PI / 30) - PI / 2;
    // if (s0 != (-1) && m0 != (-1) && h0 != (-1))
    // {
    //     setcolor(0);
    //     line(320, 240, 320 + 45 * cos(h0), 240 + 45 * sin(h0));
    //     line(320, 240, 320 + 55 * cos(m0), 240 + 55 * sin(m0));
    //     line(320, 240, 320 + 65 * cos(s0), 240 + 65 * sin(s0));
    // }

    setcolor(RED);
    setlinestyle(PS_SOLID, 5);
    line(320, 240, 320 + 45 * cos(h1), 240 + 45 * sin(h1));
    line(320, 240, 320 + 55 * cos(m1), 240 + 55 * sin(m1));

    setcolor(YELLOW);
    setlinestyle(PS_SOLID, 1);
    line(320, 240, 320 + 65 * cos(s * (PI / 30) - PI / 2), 240 + 65 * sin(s * (PI / 30) - PI / 2));

    s0 = s * (PI / 30) - PI / 2;
    m0 = m1;
    h0 = h1;
}

img