I'm trying to compare 2 strings. I'm using the Dev-C++ compiler in case that matters.
Here's the code i have:
#include <iostream>
#include <cstring>
#include <time.h>
using namespace std;
if(strcmp (password,guess) != 0){
cout << "The password is www.cpuzzle.webs.com";
}
cin.get();
return 0;
}
But regardless of what i enter in "cout << "The password is www.cpuzzle.webs.com";" still runs.
Any help with this would be awesome.
if(strcmp (password,guess) == 1){
cout << "The password is www.cpuzzle.webs.com";
}
cin.ignore( 8, '\n' );
cin.get();
return 0;
}
That fixed it displaying no matter what but now even with the correct password (the date) it won't display. Although if i run it in Debug mode it works...
You should probably use larger strings. The documentation for _strdate() says the string should be at least 9 characters long.
And remember, C/C++ arrays start at zero. guess[8] is one beyond the end of char guess[8].
And cin >> guess[8]; reads a character, not a string.
|
Many thanks. I has forgeten about the null char at the end of an array. After changing them to 9 it works perfectly. Oh and is there a way to get a string as opposed to a char?