?
Solved

Char to SYSTEMTIME

Posted on 1998-10-15
11
Medium Priority
?
646 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 400 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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