0

I am trying to make a digital clock.

I understand that the error message is due to a memory problem. My Build log don't show no error.

I have successfully included the libbgi.a as a linked library and the -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 as linker options.

What may me do to fix it?

#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();
}

Expected a beautiful digital clock face for me to edit. Now, I see:

Process returned -1073741819 (0xC0000005)   execution time : 1.849 s
Press any key to continue.
genpfault
  • 51,148
  • 11
  • 85
  • 139
JamSos
  • 19
  • 2
  • 2
    Prefer `` to ``, what attempts have you made to debug? – Mansoor Sep 17 '19 at 12:08
  • The error message code `0xC0000005` is access violation. Which means your program crashed. My guess is your compiler is too new to support winbgi. – drescherjm Sep 17 '19 at 12:09
  • I don't think the error was while compiling. That would mean the compiler crashed and you did not get an executable. ***"Process returned -1073741819 (0xC0000005) execution time : 1.849 s Press any key to continue."*** contradicts that. – drescherjm Sep 17 '19 at 12:14
  • I think adding chrono is just going to make the problem worse. I believe the problem is the last winbgi binaries were created over a decade ago and are incompatible with a modern version of mingw. That is if you are using these binaries: http://www.codecutter.net/tools/winbgim/ which state ***Library built with MingW 5.0.3 and GCC 3.4.5*** – drescherjm Sep 17 '19 at 12:19
  • So, me tried not what was denoted in Mansoor's comment. Actually me did. It not work. I enabled me compiler to use the ISO C++2011 standard in Code :: Blocks, following debug, now me debugger failed, see: verbatim. What me do? I serious. – JamSos Sep 17 '19 at 12:26
  • Downgrade codeblocks and your compiler to a much older version. Try to get one that is 10 years old or older. – drescherjm Sep 17 '19 at 12:27
  • Yeah, me done that. See: above. Not work, actually see: debugger broken. I autism. – JamSos Sep 17 '19 at 12:32
  • This is not an easy task. This is old abandoned software. – drescherjm Sep 17 '19 at 12:37
  • Hello, mate. I fixed it. Used C# instead. – JamSos Sep 20 '19 at 09:47

0 Answers0