Thank you for reading my thread.

I am experiencing an issue using struct tm and I can't figure out what I am doing wrong. I have looked at several examples and read up on the structure, but to me it all looks right. I would appreciate some fresh eyes on my code and hopefully a resolution. Below is a piece of test code that I wrote in which I receive an error stating I did not set theTime to tm* as in my larger program. By the way my compiler is MINGW if that helps.

Test Code

#include <windows.h>
#include <time.h>
#include <iostream>
using namespace std;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
while(1)
{
	time_t seconds;
	struct tm *theTime;
	time(&seconds);
	theTime = localtime(&seconds);
	int aHour = theTime.tm_hour;
	int aMin = theTime.tm_min;
	if(aHour == 1)
		if(aMin == 40)
			break;
}
cout << "Exit";

}

Terminal

$ g++ -mwindows "background app.cpp" -o bapp.exe
background app.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
background app.cpp:15: error: request for member `tm_hour' in `theTime', which is of non-class type `tm*'
background app.cpp:16: error: request for member `tm_min' in `theTime', which is of non-class type `tm*'


Thank you for reviewing my issue any help is greatly appreciated.

You need the arrow -> and not the . on lines 15 and 16 because theTime is a pointer.

commented: Thank you very simple solution. +2

Thank you very much compiled without any errors now I just have to work on some other things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.