Archerzz Posted November 8, 2005 Posted November 8, 2005 How do you get a C++ program to open another .exe file like it is going to prompt you for a password then if you get it right it will open firefox.exe but if you get it wrong it will open a batch file that will log you off. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted November 8, 2005 Posted November 8, 2005 #include <windows.h> ShellExecute(NULL, "open", "C:\\WinNT\\explorer.exe", "C:\\Program Files", "C:\\", SW_SHOW); http://msdn.microsoft.com/library/default....hellexecute.asp Share this post Link to post Share on other sites More sharing options...
Vegiemaster Posted November 9, 2005 Posted November 9, 2005 Ok, this thread is now hijacked! (Archerzz and I are working on the same program and I don't feel like starting a new thread) Basically in this portion of code I am trying to display a string after being converted from an array of chars. It works all right except for one thing. The newly created string prints what I typed but is followed by a load of gibberish. If I type "hello", it prints "hello(insert random ASCII here)" I am a total n00b at C++, so any help is much appreciated. Thanks. y=0; while(y!=5) { password[y] = getch(); printf("*"); y++; } string temp=password; cout << temp; Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted November 9, 2005 Posted November 9, 2005 I'm sure there's a function somewhere for... no... that's string class to null terminated array... Brain... locking... UP! Share this post Link to post Share on other sites More sharing options...
Vegiemaster Posted November 9, 2005 Posted November 9, 2005 (edited) Huh? Am I doing something horribly wrong? Edited November 9, 2005 by Vegiemaster Share this post Link to post Share on other sites More sharing options...
Verran Posted November 9, 2005 Posted November 9, 2005 Ok, this thread is now hijacked! (Archerzz and I are working on the same program and I don't feel like starting a new thread) Basically in this portion of code I am trying to display a string after being converted from an array of chars. It works all right except for one thing. The newly created string prints what I typed but is followed by a load of gibberish. If I type "hello", it prints "hello(insert random ASCII here)" I am a total n00b at C++, so any help is much appreciated. Thanks. y=0; while(y!=5) { password[y] = getch(); printf("*"); y++; } string temp=password; cout << temp; 574516[/snapback] Have you properly terminated your string? I can't see your whole code, so I don't know. After you build a character array out of single characters, you need to "terminate" it. Basically, you put a special character at the end that says "the string is done". It works like this: If you want to make a char array that has the word "cool" in it, it's contents would look like this Char[0] = 'c' Char[1] = 'o' Char[2] = 'o' Char[3] = 'l' Char[4] = '/0' The '/0' is the null character and it ends any string. Yes, /0 is actually two characters, but the compiler will treat it like one. When you do a cout (for instance) on that string, the output stream will get to the '/0' and know the string is done. If the '/0' is not there, the output stream will often continue outputting whatever junk happens to be in memory after the string. Not sure if this is your problem, but it is a common mistake with strings that can cause what you're seeing. Share this post Link to post Share on other sites More sharing options...
Vegiemaster Posted November 9, 2005 Posted November 9, 2005 hmm, ok but the gibberish is also present after each individual char. How would I tell each char that it is done, without deleting the char? Share this post Link to post Share on other sites More sharing options...
DECwakeboarder Posted November 9, 2005 Posted November 9, 2005 string temp=password; I don't think that this is possible, but I believe you could just use something like: string password += getch(); and that should work...Give me sometime, maybe tomorrow night I can work something out for you. Share this post Link to post Share on other sites More sharing options...
Vegiemaster Posted November 9, 2005 Posted November 9, 2005 Ok thanks I'll try something like that tomorrow. I'll be off to bed now. In case you guys don't know, I'm trying to create a password thing that writes *'s instead of what you type, but you probably know that already. Share this post Link to post Share on other sites More sharing options...
Verran Posted November 9, 2005 Posted November 9, 2005 hmm, ok but the gibberish is also present after each individual char. How would I tell each char that it is done, without deleting the char? 574532[/snapback] Nah, you don't want to terminate after every char, that's no good. I just reinstalled Dev C++ because I wanted to check this out myself I did this: #include <iostream> #include <iomanip> #include <string> #include <conio.h> using namespace std; int main() { char password[5]; int y; cout << "Enter Password: "; y=0; while(y!=5) { password[y] = getch(); printf("*"); y++; } password[5] = '\0'; cout << "\nYou entered: '" << password << "'\n"; cout << ("Press ENTER to continue.\n"); getchar (); // wait for input return 0; } That works like I think you want it to. Give it a shot and let me know if it works... PS I always get my slashes mixed up. The null char is '\0'.... NOT '/0' EDIT### Tested it without the conversion to string, and it works just fine. The string.h header should let you treat char* like a string in most cases. I updated the code above. That works for me, at least how I think it should Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted November 9, 2005 Posted November 9, 2005 The compiler treats a traditional NULL as a 0 when the \ operator is placed before it, like it does with a normal \ when it's written as \\. BAH! dangIT! YOU GOT ME PROGRAMMING AGAIN! Share this post Link to post Share on other sites More sharing options...
Vegiemaster Posted November 9, 2005 Posted November 9, 2005 Thanks alot, Verran I got it to work! Thanks everyone for your help. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now