|
well i search all the fields of time.h in the link which you gave me but i can't find any solutions. i guess i will use difftime to compare two dates which are time_t variables. but the problem is i read the birthday string from the file and need to convert this string to time_h variable and then i can compare current time and her/his birthday. i will search another ways.
|
|
|
|
|
quartaela wrote: but the problem is i read the birthday string
As I said before you will need to convert the string to its constituent numbers using strtoi() (sorry not strtod() ) and then use those numbers to populate a tm structure from which you can get the time_t value via mktime() . The documentation for all these functions is available on MSDN starting here[^]. This may all sound long and involved but I'm afraid that is the reality of programming.
The best things in life are not things.
|
|
|
|
|
well i almost near the solution. i use atoi() (i can't use strtoi() cause i guess compiler or O/S doesn't compatible with this function). so this the example code
int main(void) {
char c[11] = "2000/10/15";
printf("the number is %d", atoi(c));
return 0;
}
and the output is 2000. the problem is how can i take other numbers "10" and "15". i guess when i take this numbers i can able to solve the problem.
|
|
|
|
|
You need to split the string into its constituent parts using strtok() .
I would suggest you spend some more time learning some of the more common library functions before going further with your project. Go back to the link[^] I gave you and read through all the alphabetic list so you know (more or less) what functions are available, then you know where to look when you have specific requirements.
The best things in life are not things.
|
|
|
|
|
well finally i managed it . thanks for your help mates .
|
|
|
|
|
What about:
int y, m, d;
sscanf(c, "%d/%d/%d", &y, &m, &d); It's not the best solution, but it does give you something to explore.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Date/times held in strings are no good for doing calculations, they are only good at interfacing to humans.
Use the time_t type, it basically is the number of seconds since 01-JAN-1970.
Once you have two time_t values, you can simply subtract them and compare to some constant, such as 7*24*60*60.
[ADDED]
POSIX has a nice strptime() function to turn a datetime string into a number; Windows itself hasn't (MFC has, boost has); so your best option may well be:
- use sscanf to turn the string into struct tm; here[^] is an example that should work, provided the month is by number, not by name.
- use mktime to turn that into a time_t
- then either use difftime or simply subtract.
[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Tuesday, May 10, 2011 6:27 PM
|
|
|
|
|
MFC have CTimeSpan Class, add your date and time int one object and
bithday time in other
CTimeSpan objBithday(dd,mm,yy,hr,mm,ss);
CTimeSpan objToday(dd,mm,yy,hr,mm,ss);
CTimeSpan TimeDIff = objToday - objBithday;
Try This............ :
laugh:
|
|
|
|
|
chk this;
CString today_date_str,birth_date_str;
GetDlgItemText(IDC_DATETIMEPICKER1, today_date_str);
GetDlgItemText(IDC_DATETIMEPICKER2, birth_date_str);
m_today_dt_ole.ParseDateTime(today_date_str,0,LANG_USER_DEFAULT);
m_birth_dt_ole.ParseDateTime(birth_date_str,0,LANG_USER_DEFAULT);
CString chk_dt1=m_today_dt_ole.Format(_T("%d/%m/%Y"));
CString chk_dt2=m_birth_dt_ole.Format(_T("%d/%m/%Y"));
m_today_dt_ole.ParseDateTime(chk_dt1,0,LANG_USER_DEFAULT);
m_birth_dt_ole.ParseDateTime(chk_dt2,0,LANG_USER_DEFAULT);
COleDateTimeSpan daydiff=(m_today_dt_ole-m_birth_dt_ole);
int noofday=0;
noofday=(int)daydiff.GetTotalDays();
if(noofday<=0)
{
noofday=-(noofday);
}
noofday++;
CString Value ;
Value.Format(_T("%d"),noofday);
|
|
|
|
|
well mate i guess this is C++ or C#_? cause i can't understand the codes. i am working with C . but thanks for your help
|
|
|
|
|
I'm not the one having a problem with datetimes, I merely try to help out the OP.
And I don't think he is using or willing to use MFC.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
and also i guess this is for C#_?. .
|
|
|
|
|
If you want to be exact, you need them all: days, months and years.
The uears because of the leap day in February.
The year is a leap year if the year is divisible by four, but not by 100, except if it's divisible by 400.
Otherwise you might want to calculate days from the start of the year (takes care of different length months). Just have a table of days in each month and remember to add a day in february if it's a leap year.
|
|
|
|
|
Hi there,
I'm working on a Application developed using Visual Studio 2008 (VC++).
I'm looking for a way to get the name of the current user session using the process ID.
My intention here is to check for a particular process (AA.exe) and see this is not running for a current user.
I'm using the CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL) to get the list of process, and traverse thru the list for a matching AA.exe process. But this returns the list of processes from all users.
I've gone thru the example:
List Processes Which Are Created By Specific Users[^]
But the function LookupAccountSid() returns 0 and the get last error also returns 0.
The value of the username field seems to be NULL.
Kindly let me know, if there are any other ways to get the name of the current user session using the Process ID.
Thanks in advance.
regards,
Rajesh
|
|
|
|
|
In the call to LookupAccountSid() both cchName and cchReferencedDomainName are uninitialized.
If you set them to 255 before the call does it work then?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark. It worked after initializing those two variables.
regards,
Rajesh
|
|
|
|
|
Hi,
Can you suggest the fastest algorithm to generate unique combination of string of fixed length?
|
|
|
|
|
Unique compared to what? Are you talking about a function that will return a new string every time it's called? Or do you have a list of strings you don't want to duplicate?
|
|
|
|
|
|
|
Thanks for your reply.
But I want the all possible comabination of given string of specific length.
I am developing a password recovery utiluty so I need to pass all string combination to match the desired string.
Can you suggest me the fastest one to do so.
|
|
|
|
|
Check my post about enumerating the strings. But before you get too enthusiastic, you should read about something that might get in your way: Salt[^].
|
|
|
|
|
The fastest way would be to enumerate the possible combinations of the desired alphabet on the fly, and for each call advance a step, and remember the last unique string. For short strings, you could benefit from having them pre-generated.
|
|
|
|
|
The fastest way what I think will be using TimeStamp.
1) Get the current Time (in Milliseconds )
2) Append it to string or if comfortable, use the same as a string...
UuidCreate() is a good option but fastest will be timestamp + YourSignature
--
CHEERS!!!
|
|
|
|
|
You mean the fastest in 'code development time', I guess.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|