Thread: Converting SYSTEMTIME to struct tm

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Converting SYSTEMTIME to struct tm

    Hey,

    I have the following code which is supposed to convert the time a file was last edited, to a struct tm value that I can use with strftime(). I know I don't need to do this as I can use much easier ways, but there is a reason it must be done like this.

    Code:
    	SYSTEMTIME myTime;
    	struct tm * tm_date = new tm;
    
    	HANDLE hFind;
        WIN32_FIND_DATA FindData;
    
    	char Buffer[1000];
    	
    	hFind = FindFirstFile("C:\\SWS\\testlog.txt", &FindData);
    	
    
    	FileTimeToSystemTime(&FindData.ftCreationTime, &myTime);
    	
    	tm_date->tm_hour = myTime.wHour;
    	tm_date->tm_min = myTime.wMinute;
    	tm_date->tm_mday = myTime.wDay;
    	tm_date->tm_mon = myTime.wMonth;
    	tm_date->tm_sec = myTime.wSecond;
    	tm_date->tm_year = myTime.wYear - 1900;
    
    
    	strftime(Buffer, sizeof(Buffer), "%A, %x %X %p", tm_date);
    
    	cout << Buffer << endl;
    	delete tm_date;
    When the code gets to the strftime() function, its stops and performs an illegal operation, saying it can't access that address (or some message along those lines).

    Can anyone see what I'm doing wrong? I expect it has something to do with the pointers, because I always have problems with them. Thanks very much for any help, this means a lot to me.

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Thanks a bunch Salem that worked fine, once again I owe you one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. converting struct to tables in turbo c++
    By geft in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2008, 08:44 AM
  2. Help please im stuck
    By ItsMeHere in forum C Programming
    Replies: 7
    Last Post: 06-15-2006, 04:07 AM
  3. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM