对于学校我要做一个任务,我忙了3个星期,现在仍然没有得到远。我们需要做一个时钟,它必须是圆的,秒分钟和小时的颜色需要点亮。所以如果是上午4点25分,那些数字需要点亮。
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.
这是我现在的情况:
#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.
推荐答案确定,所以根据你的意见,它听起来像你使用的Windows,你真的只想设置一种颜色。这很容易。你想要的SetConsoleTextAttribute()函数,这里是一个非常快的例子:
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 }回到地面,你可以通过OR( | )在一起的标志来获得不同的颜色和不同的前/后理由。
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.
更多推荐
C时钟:时间亮起
发布评论