|
jung-kreidler wrote: 've tried with ILocation Com interface but it tells me that there are 'no devices detected'.
What method of ILocation gives you this error?
|
|
|
|
|
spLocation->GetReportStatus(IID_ILatLongReport, &status) returns REPORT_NOT_SUPPORTED.
The code is from one of the Microsoft samples.
|
|
|
|
|
Well, from MSDN:
Quote: REPORT_NOT_SUPPORTED
The requested report type is not supported by the API. No location providers of the requested type are installed.
Does the PC have any means to locate GPS posituion?
|
|
|
|
|
No, this is a normal PC without GPS.
I just need the country where my app was started in order to access the right webaddress provided for the country.
|
|
|
|
|
Then you need some device or some tool giving you current PC geo-coordinates....
|
|
|
|
|
As I do only need the country where my app was started the following code does the job:
std::string get_country_code()
{
HINTERNET net = InternetOpen("IP retriever",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
HINTERNET conn = InternetOpenUrl(net,
"http://ip-api.com/csv/?fields=countryCode",
NULL,
0,
INTERNET_FLAG_RELOAD,
0);
char buffer[12096];
DWORD read;
InternetReadFile(conn, buffer, sizeof(buffer) / sizeof(buffer[0]), &read);
InternetCloseHandle(net);
return std::string(buffer, read);
}
|
|
|
|
|
G lad you have solved your problem!
|
|
|
|
|
Hi
Below code does some memory corruption due to which access violation happens at sub subsequent steps
If I remove this block of code every thing is working fine. Unable to figure out the issue in the below code. Please help
while ((int)tax % 10 != 0)
{
tax *= 10;
decimals++;
}
decimalpoints = decimals-1
|
|
|
|
|
There is nothing in that code that will cause memory corruption, unless decimals and decimalpoints are pointers to a block of memory and go beyond its limit. You need to show some more of your code.
|
|
|
|
|
Both are not pointers. one issue I found with this is the loop iterates for 19 times for the value of tax = 8.995.
by end of the loop decimal = 19.
I except decimal = 3 by end of the loop
|
|
|
|
|
You are unlikely to get a valid answer doing it like that. You should use something like sprintf to convert the double value to a string and set the actual number of decimal places that you want in the format string.
|
|
|
|
|
This is not going to work as you might expect. For example, if tax has an initial value of 8.0 , it may actually be stored in memory as 8.00000000001 or something similar.
What exactly are you trying to accomplish? A better solution may be just an explanation away.
"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
|
|
|
|
|
I want to find the number of decimal point. for example 8.995 is the tax amount. I want to count number of digits after decimal point; in this case I want to get 3
|
|
|
|
|
I want to find the number of decimal point. for example 8.995 is the tax amount. I want to count number of digits after decimal point; in this case I want to get 3
|
|
|
|
|
ptr_Electron wrote: for example 8.995 is the tax amount. Which could be stored in memory as 8.9949999999999992 or something similar. Then you would get 16 (or maybe 15 , I forget) as an answer.
"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
modified 16-Oct-18 9:34am.
|
|
|
|
|
May I know the correct approach please.
|
|
|
|
|
It's still unclear as to what you are trying to accomplish. Once you have the number of digits in the mantissa, then what?
Again, if you would provide details for your end-game, we may be able to offer a better solution. Manipulating floating point numbers on a binary computer is not a trivial task.
"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
|
|
|
|
|
Thanks for response. a given decimal number. I would the count of decimal points.
For example
6.67 -? I need 2
6.9876 I need 4
1.67890 I need 5
Count of digits after decimal point
|
|
|
|
|
ptr_Electron wrote:
6.67 -? I need 2
6.9876 I need 4
1.67890 I need 5 Which are stored in memory as:
6.6699999999999999
6.9875999999999996
1.6789000000000001 or something very similar. Notice all the mantissas are the same length?
Is this just a trivial exercise for you, or are you ultimately planning on doing something with the result?
"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
modified 16-Oct-18 15:02pm.
|
|
|
|
|
As per what David has explained all doubles are actually stored subtly different to what you think because they round. I just want to extend why they round.
They round because the computer works in base 2 (0 and 1's) and you are working in decimal base 10 (0,1,2,..9)
10 does not work as a power of 2 you can go either side 2x2x2=8 OR 2x2x2x2=16 so any base 10 decimal fraction when written in base 2 will likely round
Double-precision floating-point format - Wikipedia[^]
Assuming you are on a standard Microsoft compiler many will be rounded at 52 bits long and we have no way to know what length you actually typed in.
So usually when writing doubles to screen you fix the decimal places
Here is how the standard print function does it the %.3f means take float write to 3 decimal places
printf("Double value: %.3f\n", 3.1234543747321475);
I have made a randomly long value but if you execute it only puts out 3 decimal places.
There are many conversion routines in C/C++ to convert them in fixed decimal places to screen, buffers etc.
So generally you fix the length at display or while the number is in string format, you can't work the problem in reverse the moment it stores the original length is lost.
So basically once stored there is no way to count the decimal places .. you can't do what you asked.
Lastly should add this is nothing to do with C, any language that stores numbers as doubles behaves that way.
In vino veritas
modified 17-Oct-18 10:51am.
|
|
|
|
|
Such code looks flawed.
What is the type of the tax variable?
|
|
|
|
|
Tax variable is of type Double
|
|
|
|
|
Then your code is apparently flawed.
|
|
|
|
|
I'm doing an assignment and it was told that SIZE of the array has to be const and also that I will need to create an assignment operator, but idk maybe my lecturer didn't think about it?
I have this code:
class NameList
{
private:
const int SIZE;
string* mp_list;
...
And then there's assignment operator
NameList NameList::operator = (const NameList &otherList)
{
SIZE = otherList.SIZE;
delete[] mp_list;
mp_list = new string[SIZE];
*mp_list = *otherList.mp_list;
}
This will not work since you can't change const. But it's bad if I don't change the SIZE variable. Is there a way to create an assignment operator with const variable? Or is it ok if the size of the array is not const or it's bad programming? What would you do?
|
|
|
|
|
There could be a lot of guesswork, but, as a matter of fact, I suppose you should ask your Lecturer.
|
|
|
|