时钟在C:时间补光灯 [英] Clock in C: Time light up
问题描述
有关学校里,我必须做一个分配而言,我忙着它样3周了,仍然没有带变得远。我们需要有是圆的钟的秒分钟和小时的颜色要亮起来。所以,如果是上午04时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,你真的只是想设置一个颜色。这是pretty容易。您希望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:时间补光灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!