|
Charlie,
charlieg wrote: I guess it's in a header file but not in the binary.
Thank you
You are welcome.
|
|
|
|
|
I am working on c++ desktop application , i have to allow one time access for each employee per a day,
the question is how to interact with access control and open the door through it
(the access control has its dadecated software to open the door)
a looked for the API from its proper website but they do not offer it
now i have just the access control driver.
|
|
|
|
|
The question is impossible to answer since we have no idea how the access control software works. You need to contact the manufacturers of the door for help.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
asked and answered in QA, I think.
Keep Calm and Carry On
|
|
|
|
|
|
First off, I'm not asking for anyone to write code for me. I would like to programmatically drop a Microsoft Project application into my Windows application in a specified location and then be able to drag and drop a file onto the container app? Any hints on how? Thanks
|
|
|
|
|
Glenn Meadows 2022 wrote: programmatically drop a Microsoft Project application into my Windows application What exactly do you mean by that? As to your second question, drag and drop of files is fully supported in Windows; Google will find you plenty of samples.
|
|
|
|
|
Glenn Meadows 2022 wrote: I would like to programmatically drop a Microsoft Project application into my Windows application in a specified location... This reminds me of what COM was used for decades ago.
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
<pre lang="C"></pre>In my program, I am asking the user to input a date(in just integers ie 12 31 2019 367) and the number of days they add to it. In one of my functions, this is precisely what I am doing.
The user inputs 12 31 2019 367, and the program is meant to print 1 1 2021, but instead prints 1 1 2020(a year behind)...
What I did(Sorry for a lot of code, I tried to keep it simple and clean):
int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void add_days_to_date(int *mm, int *dd, int *yy, int days_left_to_add)
{
int days_left_in_month;
while(days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
// days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year(*yy) == true)
{
days_left_in_month++;
}
} // end while
printf("after while\n");
if(days_left_to_add > days_left_in_month)
{
days_left_to_add -= days_left_in_month;
*dd = 1;
if(*mm == 12)
{
*mm = 1;
(*yy)++;
}
else
{
(*mm)++;
}
}
else
{
*dd += days_left_to_add;
days_left_to_add = 0;
}
}
int main()
{
int mm, dd, yy, days_left_to_add;
printf("Please enter a date between the years 1800 and 10000 in the format mm dd yy and provide the number of days to add to this date:\n");
scanf("%d %d %d %d", &mm, &dd, &yy, &days_left_to_add);
// printf("\nREAD\n");
//These are pointers, so they have to be at certain location i.e. int* mm = &mm
add_days_to_date(&mm, &dd, &yy, days_left_to_add);
printf("%d %d %d\n", mm, dd, yy);
}
What I got after inputs:
Inputs: 12 31 2019 367
Output: 1 1 2020(meant to be 1 1 2021)
Thank you in advance and for your time and patience...</pre>
|
|
|
|
|
You have to debug your code to see where, how and why it "calculates" wrong result!
|
|
|
|
|
Your code is somewhat confusing, but I did notice the following:
int days_left_in_month; while(days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year(*yy) == true) {
days_left_in_month++;
}
}
The actual logic needed is as follows:
Set days_in_year to the actual number of days up to the date given, which in the case above should be 365.
Add days_to_add to days_in_year.
While days_in_year > 365
{
add 1 to year
subtract 365 from days_in_year
}
Use the remaining value of days_in_year to calculate the month and day.
Obviously an adjustment for leap years will be needed somewhere in there.
|
|
|
|
|
As Victor was saying, this is the tough part of a programmer's job: finding the errors in your code. Most of the time you are on your own when doing it but in this case I'll try to do part of it with you hoping the experience will be useful.
Before we start, when posting code here, try to paste it between the <pre></pre> tags. It makes it for a much nicer and easier to read code.
int days_in_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void add_days_to_date (int* mm, int* dd, int* yy, int days_left_to_add)
{
int days_left_in_month;
while (days_left_in_month > 0) Now, ask yourself, what is the value of days_left_in_month when the computer tries to evaluate the while loop for the first time? The answer is that it is not known. This is an "uninitialized local variable" bug and it is very common. The compiler has reserved space for the variable but its content can be anything. We have to fix this.
while (days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year (*yy) == true)
Oops, here is another bug: you wrote days_in_month[2] which is 28 and clearly not zero but what you probably had in mind was more like:
if (month == 2 && is_leap_year(*yy) == true)
If we fix the two errors we found your code will be looking something like this:
void add_days_to_date (int* mm, int* dd, int* yy, int days_left_to_add)
{
int days_left_in_month;
days_left_in_month = days_in_month[*mm] - *dd;
if (*mm == 2 && is_leap_year (*yy))
days_left_in_month++; Now it's really the time to start a loop but this loop will have to run until the days_left_to_add is greater than days_left_in_month .
Here I'll stop and let you finish the code. Post back the result and I'll give you more feedback on algorithm and style.
EDIT - I see that while I was writing my long convoluting answer Richard had already made the same points in a more concise form
Mircea
|
|
|
|
|
Yes, mine was concise, but your comments still added some good detail.
|
|
|
|
|
Hi
I am getting invalid comparator for the following code and I just dont get it at the very end there is always a path to return
struct usingrange
{
ESDID esdid;
int start;
int end;
usingrange() { start = 0; end = 0; return; }
bool operator<(const usingrange x) const {
if (esdid <= x.esdid) return esdid <= x.esdid;
if (start <= x.start) return start <= x.start; if (end <= x.end) return end <= x.end;
else
return FALSE;
|
|
|
|
|
Shouldn't you be passing usingrange as a reference to your comparison function?
bool operator<(const usingrange& x) const
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
It’s a member of key type
|
|
|
|
|
this is were I am getting the exception at the line with STL_VERIFY
template <class _Pr, class _Ty1, class _Ty2,
enable_if_t<is_same_v<_Remove_cvref_t<_Ty1>, _Remove_cvref_t<_Ty2>>, int> = 0>
constexpr bool _Debug_lt_pred(_Pr&& _Pred, _Ty1&& _Left, _Ty2&& _Right) noexcept(
noexcept(_Pred(_Left, _Right)) && noexcept(_Pred(_Right, _Left))) {
const auto _Result = static_cast<bool>(_Pred(_Left, _Right));
if (_Result) {
_STL_VERIFY(!_Pred(_Right, _Left), "invalid comparator");
this is my code
struct usingrange
{
ESDID esdid;
int start;
int end;
usingrange() { start = 0; end = 0; return; }
bool operator<(const usingrange& x) const {
if (esdid < x.esdid)
return esdid < x.esdid;
if (start < x.start)
return start < x.start;
if (end < x.end) return end < x.end;
else
return x.end < end;
when I change mt code to
bool operator<(const usingrange& x) const {
return start < x.start;
}
everything works I dont get it the operator is excepting a bool retrun code true or false in either I retrun that
|
|
|
|
|
Does your ESDID class have an operator<() function? If not, add one.
|
|
|
|
|
Thank you so much actually everything is a structure I am a very open person
I got to tell you something you C++ guys a geniuses
|
|
|
|
|
still getting the exception if the key to the map is a structure
consisting of a char[4] and 2 int how would I set < operator
the only way I got it to work
was by return int1 < x.int1
what would like to do
is concatenate all of them in 12 bytes and compare 12 bytes against 12 bytes
thanks
|
|
|
|
|
Since my data was 12 bytes long I was lucky there happened to be a data type 16 bytes long a "long double" I just filled the first 4 bytes with zeros and
;
struct usingrange
{
ESDID esdid;
int start;
int end;
usingrange() { start = 0; end = 0; return; }
bool operator<(const usingrange& x) const {
union
{
long double a;
char str1[16];
}c;
union
{
long double b;
char str2[16];
}d;
::memset(&c.str1, 0x00, 16);
::memset(&d.str2, 0x00, 16);
::memcpy(&c.str1[4], &esdid, 4);
::memcpy(&c.str1[8],&start,4);
::memcpy(&c.str1[12], &end, 4);
::memcpy(&d.str2[4], &x.esdid, 4);
::memcpy(&d.str2[8], &x.start, 4);
::memcpy(&d.str2[12], &x.end, 4);
return c.a < d.b;
}
};
|
|
|
|
|
That has a couple of issues. Firstly, you are invoking undefined behavior: Union declaration - cppreference.com
Secondly, you're expecting that the bit patterns of 2 doubles can be compared. This may not be the case, as you may a NaN this way, and then any comparison will return false:
[k5054@localhost tmp]$ cat example.c
int main()
{
double d = 0.0 / 0.0; // produces NaN
printf("1.0 < d = %d\n", 1.0 < d);
printf("d < 1.0 = %d\n", d < 1.0);
printf("d == d = %d\n", d == d);
}
[k5054@localhost tmp]$ gcc example.c -o example
[k5054@localhost tmp]$ ./example
1.0 < d = 0
d < 1.0 = 0
d == d = 0
[k5054@localhost tmp]$
As we can see in the above code, NaN compared to anything, even itself returns false.
If all you want to do is compare bits, you might as well just go ahead and use memcmp()
*#35;include <cstring>
struct usingrange {
ESDID esdid;
int start;
int end;
bool operator<(const usingrange& x)const {
return ::memcmp(this, &x, sizeof(*this)
}
}; This relies on the fact that the sizeof a struct or a class is the size of its individual members. This only becomes tricky if your struct/class includes STL or other objects like std::string or std::vector.
Keep Calm and Carry On
|
|
|
|
|
The return using memcmp as operands will get an exception in order to get around this I need to to have to have the syntax return operand1 < operand2 truthfully the order of the items is not that important as long as I am able to retrieve the data by key thanks
|
|
|
|
|
I think you're making it too complicated:
struct ESDID
{
char c[4];
bool operator<(const ESDID& other) const
{
return c[0] < other.c[0] && c[1] < other.c[1] &&
c[2] < other.c[2] && c[3] < other.c[3];
}
}
struct usingrange
{
ESDID esdid;
int start;
int end;
bool operator<(const usingrange& other) const
{
return esdid < other.esdid && start < other.start &&
end < other.end;
}
}
I've used && and < because you do not want operator<() to return true for two different objects when you swap them around.
|
|
|
|
|