C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-22-2008, 03:27 PM   #1
Registered User
 
Join Date: Oct 2008
Posts: 7
Question What am I doing wrong with struct tm?

I have look around and around, and now matter what I seem to do I just can't seem to get this to work. I don't understand what I'm doing wrong. I've tried it with 'struct' in front of 'tm *today' as well

When I debug it, I get "Error 2 error C2228: left of '.tm_mon' must have class/struct/union". Which I don't get since I thought I had declared it.

Code:
#include <stdio.h>
#include <iostream>
#include <ctime>

using namespace std;

int main ()
{

	char test;
	time_t now;
	tm *today;

	time(&now);
	today=localtime(&now);

	cout << today.tm_mon << endl;

	cout << "Did it work?";
	cin >> test;

  return 0;
}
What am I doing wrong?
MGrancey is offline   Reply With Quote
Old 11-22-2008, 03:30 PM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
It's a pointer to a struct.

So it's
today->tm_mon;
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 11-22-2008, 03:31 PM   #3
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,354
Since today is a pointer, it should be today->tm_mon.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Old 11-22-2008, 08:36 PM   #4
Registered User
 
Join Date: Oct 2008
Posts: 7
Lightbulb Thanks

Thanks, that was a silly thing to miss when I read that several times.
MGrancey is offline   Reply With Quote
Reply

Tags
date, localtime, struct tm, time

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link List math t014y C Programming 17 02-20-2009 06:55 PM
Assignment HELP!! cprogrammer22 C Programming 35 01-24-2009 02:24 PM
Help please im stuck ItsMeHere C Programming 7 06-15-2006 04:07 AM
Search Engine - Binary Search Tree Gecko2099 C Programming 9 04-17-2005 02:56 PM
Request for comments Prelude A Brief History of Cprogramming.com 15 01-02-2004 10:33 AM


All times are GMT -6. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22