Solved

Char to SYSTEMTIME

Posted on 1998-10-15
11
639 Views
Last Modified: 2013-12-03
I am reading a date in form DD/MM/YYYY as a string and trying to allocate to a SYSTEMTIME structure ie; rLogSystemtime.wDay = atoi(cLogfile_day);
wDay is classed asa WORD in the help so how do I get such a conversion to work ?
0
Comment
Question by:ssherlock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1415269
rLogSystemtime.wDay = (WORD) atoi(cLogfile_day);

let me know if you have questions.
0
 

Author Comment

by:ssherlock
ID: 1415270
That causes an illegal operation and the programme dies horribly! (which was what was happening before :(
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415271
The source of problem must occur before that.  Post more of your code.  What is cLogeFile_day set to?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:ssherlock
ID: 1415272
<Red face> You're right - the command did actually work but I was using printf to see the result and was trying to display a character (%s) rather than integer (%d).  Thanks for your help, now sorted (what's sadder is that I had done it correctly in the first place :))
0
 

Author Comment

by:ssherlock
ID: 1415273
nietod,
Have you any idea why the following fails ?       

SYSTEMTIME rSystemtime;
SYSTEMTIME rLogSystemtime;
FILETIME rFiletime_sys;
FILETIME rFiletime_log;

rLogSystemtime.wDay = (WORD) atoi(cDay);
rLogSystemtime.wMonth = (WORD) atoi(cMonth);
rLogSystemtime.wYear = (WORD) atoi(cYear);

/* Convert SYSTEMTIME structure to FILETIME structure*/
SystemTimeToFileTime(&rLogSystemtime,&rFiletime_log);

GetLastError() returns a "Cannot Create A File When That File Already Exists" - no files are involved (I'm using it for date calculations) ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415274
In what way is it failing?  What are cDay, cMonth, and cYear?  What is the return value from SystemTimeToFileTime()?
0
 

Author Comment

by:ssherlock
ID: 1415275
cDay etc are bits taken from a file so cDay may be 15, cMonth=10 and cYear=1998.  The SYSTEMTIME structure set with these and then converted to a FILETIME structure.  If SystemTimeToFileTime fails it returns FALSE and can be read by using GetLastError() which gives the result I mentioned above.  I'm stumped.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415276
>> cDay etc are bits taken from a file so cDay may be 15, cMonth=10 and cYear=1998
"may be"?  what ARE they?  if these values are not valid, the function will fail.  Have you verified that they are valid?  Have you verified that atoi() has returned the correct value?
0
 

Author Comment

by:ssherlock
ID: 1415277
Sorry, they are int, or rather (WORD) int.  I can sprintf(somestring,"%d/%d/%d",cDay,cMonth,cYear) with no problem.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415278
You are missing the point.  You need to verify that the VALUES STORED IN the month day and  year are valid.  If month is set to 13, the function will fail.  There is no 13th month.  etc.  Also make sure the year specifies the century.  It should be 1988 for the current year, not just 88.

Work backwards.  Check every one of the values in the SYSTEMTIME structure.  They must all be valid other than the day of the week.  (This includes the time members, I assume you are setting them as well.)  If any of these are invalid, the function will not work.
0
 

Author Comment

by:ssherlock
ID: 1415279
You were right.  The values I was using were OK but I had forgotten to initialise the times (wHour, wMinute, wSecond and wMilliseconds).  Once I had allocated 0 to each of those it worked a treat.

Thanks for your help and patience!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question