|
#include <direct.h> // for getcwd
#include <stdlib.h>// for MAX_PATH
#include <windows.h>
#include <iostream> // for cout and cin
using namespace std;
// function to return the current working directory
// this is generally the application path
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
int main()
{
// _MAX_PATH is the maximum length allowed for a path
char CurrentPath[_MAX_PATH];
// use the function to get the path
GetCurrentPath(CurrentPath);
// display the path for demo purposes only
char temp[_MAX_PATH];
char temp1[_MAX_PATH]={"C:\\Program Files"};
if(CurrentPath==temp1){
cout << CurrentPath << endl;
cout << temp1 << endl;}
cout << "Press Enter to continue";
cin.getline(temp,_MAX_PATH);
return 0;
}
Thats what I have, and it outputs the current path and what temp1 holds when the if statement is gone, but no matter what I cannot get the program to check if its in the right directory. Any more tips?
|
|
|
|
|
gamefreak2291 wrote: if(CurrentPath==temp1){
You should be using some sort of string compare routine here (e.g., strcmp() ).
Have you used the debugger to step through the code?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thanks again, opened up my book, went right to str functions found strcmp and here is the working code:
#include <direct.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
using namespace std;
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
int main()
{
char CurrentPath[_MAX_PATH];
GetCurrentPath(CurrentPath);
char temp[_MAX_PATH];
char temp1[_MAX_PATH]={"C:\\Program Files\\uTorrent"};
if(strcmp(CurrentPath, temp1)==0){
cout << CurrentPath << endl;
cout << temp1 << endl;}
cout << "Press Enter to continue";
cin.getline(temp,_MAX_PATH);
return 0;
}</iostream></windows.h></stdlib.h></direct.h>
|
|
|
|
|
Use GetModuleFileName().
The other response is not going to work in all cases (GetCurrentDirectory) since your program could be run from a shortcut on the desktop, and that shortcut could specify a different working directory.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I've been trying to read up on some options of what I might be able to use. Perhaps, it can be better explained if I tell you what I would like to do.
I was hoping for a bit oriented class that not only provided storage on a per bit basis but also had the capability to provide an actual value. If you have binary data say in the form of messages in various formats, some of the binary data may use a single bit or a group of bits. In other words, a single bit is really a bit flag or boolean true or false, while a group of bits is a value. Of course, the groups of bits and bit flags may actually be intermixed say in a 16-bit word.
I've got 16-bit words (comprised of bit flags and bit field groups). It would be kind of nice to group the bits into bit fields and flags, e.g. say a 16-bit field comprised of three 4-bit fields, a 2-bit field and two single bit flags. I would like to make the contents of these bit fields somewhat human readable by decoding the binary in the same left to right order as they are stored in binary. We typically do this by using structures. This works fine for decoding but I would like to do something different.
If I could wrap these bit fields and flags into groups within an array or individual objects, I then would have the capability to name or label each object, bit field or group, and perform comparisons on similar data. In other words what may be a 4-bit field in one message may be a 3-bit field in another type of message, by writing a conversion routine between the two types, I still can make a similar comparison and not an exact comparison.
I'd have to design my own class but if I inherit from one of the previously mentioned classes, which one do you think would be best? For now, I have fixed data sizes but may need more flexible and unknown (until runtime) data sizes in the future. I'm not sure if I would want to wrap all of the bitfields or groups of bits that comprise a single message into a single object that would have a message type as a data member but I think I would like to.
|
|
|
|
|
JohnnyG wrote: if I inherit from one of the previously mentioned classes, which one do you think would be best?
JohnnyG wrote: may need more flexible and unknown (until runtime) data sizes
I'd alter each of your fields to be a method (rather than a data member) and extract it using bit-field extraction.
For instance, say we have a field 'A':
class MyBitFields
{
public:
MyBitFields(uint16_t compositeValue) : value_(compositeValue)
{
}
void SetA(unsigned int offset, unsigned int size) { aOffset_ = offset; aSize_ = size; }
unsigned int getA() { return (value_>>aOffset_) & ((1<<aSize_)-1); }
private:
uint16_t value_;
uint8_t aOffset_;
uint8_t aSize_;
};
?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That's an interesting idea and may be exactly what I need since I am not intending to store every binary data value read from a file into the MyBitFields class permanently but rather to help me decode and perhaps to compare. I also could have a data member inside of MyBitFields and even have conversion modifiers inside of the class.
Additionally, I could also create an array of MyBitFields, one array per message
Thanks for the info!
|
|
|
|
|
I've noticed that sprintf() does some interesting things with the numbers, for example:
double : 8.38750000 sprintf: 8.387
double : 9.23750000 sprintf: 9.238
The final sprintf() was achieved with code like this:
double d = 9.23750000;
sprintf( tmp, "%0.3f", d );
In the case of 8.3875, no rounding appears to taking place. In the case of 9.2375, we get rounding! Is this normal? Is there a way to prevent this?
Bah humbug, it helps to actually examine the damn number more closely. Never mind!
Thanks to everyone who answered below!
modified on Monday, April 20, 2009 4:41 PM
|
|
|
|
|
You have got different (1 up, 1 down) rounding there, Jim - but I suspect it might be bankers rounding[^]?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
Both your numbers look very regular to humans, using decimal notation.
None of these numbers get represented exactly in floating-point, so it happens one of them is slightly less, the other slightly more than the values you would hope. Of course it is the internal value that gets rounded, not the one you had in mind.
Check by printing more decimals, e.g. "%0.8f"
|
|
|
|
|
Follow me into the IEEE journey (i.e. mere experimenal evidence of Luc's argument), check out the hexadecimal representation of the numbers:
40 20 c6 66 66 66 66 66
40 22 79 99 99 99 99 9a
From [^] we know that:
sign, for both number is 0 , hence they are positive (what surprise!).
Exponent is 0x402 for both numbers, i.e. 1026 , i.e. 3 , since the IEEE standard biases the exponents of 1023 .
Now the important part, the fraction:
First number has 0x0c66666666666 * 2^-52 , i.e. 0.048437499999999911182158029987477 (windows calculator is great!). following the IEEE prescription we add the implicit 1 obtaining 1.048437499999999911182158029987477 .
Second number has 0x279999999999a * 2^-52 , i.e. 0.15468750000000008881784197001252 . Adding the implicit 1 makes 1.15468750000000008881784197001252 .
Finally we get 1.048437499999999911182158029987477 * 2^3 = 8.3874999999999992894572642398998 (first number), 1.15468750000000008881784197001252 * 2^3 = 9.2375000000000007105427357601002 hence follows the 'strange printf behaviour'.
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]
|
|
|
|
|
I am trying to build an application with OpenGL in a MFC dialog
can any one help me in drawing text in the openGL window..
any help would be appreciated
|
|
|
|
|
Google[^] brings this[^] up - helps?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
sorry i dint get it
|
|
|
|
|
i've seen this video dint help much
thanks anyways
|
|
|
|
|
What about the "Text Version" link?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I've just fixed a bug in one of our internal programs that was failing to release a COM interface (IXMLDOMNode returned by IXMLDOMDocument::createNote if you're interested) which resulted in a memory leak. The leak was occuring 192 times every 15 seconds the program was running and, given that it's a background task designed to run continously, you can seen the number of leaks quickly rises to a huge number (over 46000 per hour).
What I need to know is, should a Windows 2008 Terminal Server be able to handle that kind of problem and what resouce limits could the server have been hitting? The private bytes count was only up to 200MB which is nothing when the machine has 14GB. We've had some strange slow downs on that particular server (to the point where it needs to be restarted) and I'm trying to work out if this particular program could have been the cause.
|
|
|
|
|
I have integrated a close button on my Windows form written in Visual C++, and when the user clicks that button, it deletes the generated batch files from the program and then exits the application. The problem lies in the fact that the API also has that little red x up in the corner... How can I force the API to "clean" the subdirectory and delete the batch files that were generated before the program closes just concerning the built in close feature on all Windows applications? (By the close feature, I am referring to the X symbol in the upper right hand corner of the form)
|
|
|
|
|
turkmeistr1 wrote: The problem lies in the fact that the API also has that little red x up in the corner...
An API is a function or a set of functions. What do they have to do with a UI component?
turkmeistr1 wrote: How can I force the API to "clean" the subdirectory and delete the batch files that were generated before the program closes...
From where are you doing this clean-up?
Are you using MFC?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sorry, I'm new to Visual C++ and am not familiar with terminology. Basically, I have a UI and I want it to execute the same code for this button (code shown below) when the user clicks the close button in the upper right hand corner that is built into the form.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (File::Exists("cmd\\getmac.bat"))
File::Delete("cmd\\getmac.bat");
if (File::Exists("cmd\\showip.bat"))
File::Delete("cmd\\showip.bat");
if (File::Exists("cmd\\tracert.bat"))
File::Delete("cmd\\tracert.bat");
if (File::Exists("cmd\\reset.bat"))
File::Delete("cmd\\reset.bat");
if (File::Exists("cmd\\restart.bat"))
File::Delete("cmd\\restart.bat");
if (File::Exists("cmd\\ping.bat"))
File::Delete("cmd\\ping.bat");
Application::Exit();
}
|
|
|
|
|
turkmeistr1 wrote: Sorry, I'm new to Visual C++ and am not familiar with terminology.
Or the difference between Unmanaged and Managed C++.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sorry, didn't realize this was a flaming thread. I'll do my best to ask for help somewhere else.
|
|
|
|
|
#include <conio.h>
#include <iostream.>
#include <windows.h>
using namespace std;
char password1[25];
int x=1;
int i=0;
int q;
int main()
{
do{
cout << "Enter a test password: " ;
for(i=0;i<25;i++){
password1[i]=getch();
if(((password1[i]>=65)&&(password1[i]<=90)) || ((password1[i]>=97)&&(password1[i]<=122))
|| ((password1[i]>=48)&&(password1[i]<=57)) || ((password1[i]>=35)&&(password1[i]<=38))
|| ((password1[i]>=40)&&(password1[i]<=42)) || ((password1[i]==33))||((password1[i]==64))
|| ((password1[i]==94)) || ((password1[i]==32))){cout << "*";
i+1;}
if(password1[i]==13){i-1; goto end;}
else{i-1;
cout << "";}
}
end:
for (i; i < strlen(password1); i++){
password1[i] = '\0';}
cout << "\nYour password is ";
for(q=0;q<i;q++){cout><< password1[q];}
Sleep(2000);
if(password1[q]='p','a','s','s','w','o','r','d','\0'){goto end1;}
system("cls");
}while(x=1);
end1:
cout << "\nIT WORKS!";
getch();
return 0;
}</windows.h></iostream.></conio.h>
I cannot seem to get the program to check the password properly, it either doesn't work. Or anything works
|
|
|
|
|
gamefreak2291 wrote: if(((password1[i]>=65)&&(password1[i]<=90)) || ((password1[i]>=97)&&(password1[i]<=122)) || ((password1[i]>=48)&&(password1[i]<=57)) || ((password1[i]>=35)&&(password1[i]<=38)) || ((password1[i]>=40)&&(password1[i]<=42)) || ((password1[i]==33))||((password1[i]==64)) || ((password1[i]==94)) || ((password1[i]==32))){cout << "*"; i+1;}
Have you considered isdigit() , isalnum() , isalpha() , isxdigit() , etc? It won't necessarily solve your problem (I've not looked to see what the actual problem is), but making it easier to read won't hurt.
gamefreak2291 wrote: if(password1[q]='p','a','s','s','w','o','r','d','\0'){goto end1;}
Is this supposed to do something?
gamefreak2291 wrote: }while(x=1);
Look at this line real close. Also, your i+1 and i-1 statements are not doing what you expect.
gamefreak2291 wrote: for(q=0;q<i;q++){cout><< password1[q];}
Does this even compile?
What warning level are you using?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
no, i have not considered the others, because it took long enough to get the ascii values going.
DavidCrow wrote: if(password1[q]='p','a','s','s','w','o','r','d','\0'){goto end1;}
yes, that takes you to the end which prints that the password works.
DavidCrow wrote: }while(x=1);
okay, im looking at it. It does exactly what it is supposed to, that bit of code is only in the program at this point for debugging purposes, it allows the user to keep trying to get the correct password.
As for i+1, and i-1.. i++ and i-- was not working properly, I changed them to +1 and -i, then had them print to make sure they were working.
And of course it compiles. the reason why "for(q=0;q<i;q++){cout><< password1[q];}" is in the code is because password1[i] allows you to enter 25 characters max, and if you only enter 5 characters, the rest of them are filled in with null terminators. However, I don't want my password to be full of null terminators, so if i input 5 characters, i is currently 5, so i have q=i; then i fills out with the rest of the array with null terminators. Then the program prints password1[q] from 0-5, which is really like printing password1[0], password1[1], password1[2], password1[3], password1[4], and password1[5]. I previously had the program print the entire array however it was over lapping on multiple tries, so now it only prints the needed numbers.
Thanks again for the help
|
|
|
|
|