我正在尝试制作一个数字时钟。
我了解错误消息是由于内存问题引起的。我的构建日志没有显示任何错误。
我已成功将 libbgi.a 包含为链接库和-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
链接器选项。
我可以做些什么来解决它?
#include <graphics.h>
#include <time.h>
int main()
{
int gd = DETECT, gm;
char driver[] = "C:\\TC\\BGI";
initgraph(&gd, &gm, driver);
time_t rawTime;
//Created a pointer variable of tm struct. Variable name is currentTime.
struct tm * currentTime;
char a[100];
while(1)
//Always true
{
//%I=%DD, %M=%D, %S=%C;
rawTime = time(NULL);
currentTime = localtime(&rawTime);
strftime(a, 100, "%I:%M:%S", currentTime);
//function copies the third value, see: 'S', into the first argument ("a").
//a holds the value %I:%M:%S".
//%I will be replaced by Hour in 12h format (01-12).
//%M will be replaced by Minute (00-59).
//%S will be replaced by Second (00-61).
//'100' is the maximum number of characters to be copied to 'a'.
setcolor(11);
settextstyle(3, HORIZ_DIR, 10);
outtextxy(200, 100, a);
//see: color, location.
strftime(a, 100, "%p", currentTime);
settextstyle(3, HORIZ_DIR, 2);
outtextxy(600, 8, a);
delay(1000);
}
strftime(a, 100, "%a, %d %b, %Y", currentTime);
settextstyle(3, HORIZ_DIR, 5);
outtextxy(130, 310, a);
//%p format is for AM or PM designation.
//%a format specifier is for abbreviated weekday name. Ex: Mon, Tue, Wed etc...
//%d format specifier is for the day of the month (1-31).
//%b format specifier is for abbreviated month name. Ex: Jan, Feb, mar etc...
//%Y formate specifier is for the year Ex: 2015.
getch();
closegraph();
}
期待一个漂亮的数字钟面供我编辑。现在我明白了:
Process returned -1073741819 (0xC0000005) execution time : 1.849 s
Press any key to continue.