C时钟:时间亮起

编程入门 行业动态 更新时间:2024-10-11 21:23:50
本文介绍了C时钟:时间亮起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于学校我要做一个任务,我忙了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时钟:时间亮起

本文发布于:2023-11-27 14:17:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638417.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:亮起   时钟   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!