C 中的时钟 : Time light up

标签 c colors clock

<分区>

为了上学,我必须做作业,我已经忙了大约 3 个星期了,但还没有完成。我们需要制作一个必须是圆形的时钟,秒分和小时的颜色需要亮起。因此,如果现在是凌晨 4:25,则这些数字需要亮起。

这是我现在得到的:

   #include <stdio.h>
   #include <time.h>
   #include <conio.h>
   #include <unistd.h>
   #include <stdlib.h>
   #include <windows.h>

    int csecs (int cseconds );

    void main (int sec, int min){
    printf("Hallo! Veel plezier met het bekijken van de tijd!");
    getch();
        while (sec)
            {
            time_t cseconds;
            cseconds = time (NULL);
            printf ("De Tijd: ");
            printf ("%d:", csecs( cseconds )/60/60%24+1);
            printf ("%d:", csecs( cseconds )/60%60 );
            printf ("%d", csecs( cseconds )%60 );

            Sleep(1000);
            system("cls");
        }

    }

    int csecs (int cseconds)
    {
        return cseconds;

    }

谁能告诉我怎么可能做到这一点?我不是要你做我的功课..我只是真的需要一些帮助。

最佳答案

好的,根据您的评论,听起来您使用的是 Windows,您真的只是想设置一种颜色。这很容易。您需要 SetConsoleTextAttribute() 函数,这是一个非常简单的示例:

#include <stdio.h>
#include <Windows.h>
#include <string.h>

void main()
{
    printf("Hello\n");  // Print white text on black output
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
    printf("Hello Again!\n");  // Print Red text on black output
    getchar(); // Pause the program to admire the colors
}

为了进一步突出显示,您还可以更改背景,您可以将标志或 (|) 组合在一起以获得不同的颜色和不同的背景/前景。

所以如果你想在绿色背景上做红色文字(出于某种原因)你可以这样做:

FOREGROUND_RED | BACKGROUND_GREEN

enter image description here

我想这就是您真正想要的,现在您可以把它应用到您的时钟上,获取时间并突出显示颜色。

关于C 中的时钟 : Time light up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13193815/

相关文章:

c - 如何让这个程序接受输入?

c# - 需要帮助防止无限循环。属性设置

java - 在 Java 时钟中打印的第 60 分钟

c++ - Sleep() 函数用法

c - 我如何处理指针?

清除 Linux C 中终端程序的输出

c - 从变量初始化结构中的字段

pdf - 如何在打印前从 PDF 文本中去除黑色背景

css - 向 CSS 颜色变量添加不透明度

c++ - C++ 中带线程的时钟函数