Clock in C: Time light up [closed]

╄→гoц情女王★ 提交于 2020-01-02 07:14:09

问题


For school I have to do a assignment, Im busy with it for like 3 weeks now and still havn't gotten far. We need to make a clock that has to be round and the colours of the seconds minutes AND hours need to light up. So if it's 4:25 am those numbers need to light up.

This is what I've got right now:

   #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;

    }

Can anyone tell me how I could possibly do this? I'm not asking you to do my homework.. I just really need some help.


回答1:


OK, so based on your comments it sounds like you're using Windows and you really just want to set a color. That's pretty easy. You want the SetConsoleTextAttribute() function, here's a very quick example:

#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
}

For further highlighting you can also change the back ground, you can OR (|) together flags to get different colors and different back/fore grounds.

So if you wanted to do red text on a green back ground (for some reason) you could do:

FOREGROUND_RED | BACKGROUND_GREEN

I think that's all you were really asking for, now you can take that and apply it to your clock, getting the time and highlighting the color.



来源:https://stackoverflow.com/questions/13193815/clock-in-c-time-light-up

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!