|
/quick look
the problem is probably in your call to realloc() - the parameter specifies the new number of bytes the buffer should be, not the number of extra bytes you want.
you should also not use the variable name cin - it has special meaning in C++
and ditch the long if-else statement at the end! look at isalpha(), ispunct() and toupper(). A-Z are contiguous in ASCII so toupper(ch) - 'A' will map the letter in ch to a value between 0 and 25.
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Thanks.I changed the 'cin' to 'ci' and adjusted the realloc to the following yet I cannot change the long if else statement because of my main program (long story involving multiplicative inverses of modular functions), so the realloc is now...
ci = (char *)realloc(ci, (/**/ sizeof(char) * (20+(10*i)) /**/) );
which should do what I want (realloc 10 char every loop if 10 or more are typed), yet I still recieve this:
"Expression: _CrtIsValidHeapPointer(pUserData) assertion failure"
, what on earth does that mean? I have a feeling that I have much more than just one problem. I must addmit though that this has become quite fun, so far in class i've picked up everything with ease, seeing how complicated C can get is really cool to me(even though i think that i have no idea how complicated C can get). anyway if you have ANY other ideas that would be great!
|
|
|
|
|
This error means that you've passed a pointer in to the system that wasn't given to you by the system.
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Thanks for your help i've fixed the problem, i made a really dumb mistake. now comes the next point; so now how should i go about dynamicly declaring a n-dimentional array (i mean a nxn matrix, if my language was wrong)???
|
|
|
|
|
If you're not using the STL, the easiest way is to define a 1-D array and manually convert the 2-D co-ordinates to 1-D:
<br />
int width=10 ;<br />
int height=20 ;<br />
char* pArray = new char[ width * height ] ; <br />
<br />
int x=5 ;<br />
int y=2 <br />
char ch = pArray[ width*x + y ] ; <br />
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Anyone know where to change the default file name extension for documents in VC7. It was part of the project setup in VC6, but I did not see it when I set up a new project in VC7. TIA.
Matt (Padawan Learner)
|
|
|
|
|
|
Hi,
I am using an encrypted password in an INI file using the CryptoAPI (cryptography.cpp and .h) which is read from the INI file and converted back into text for checking by my program. However, certain symbols generated by the encryption cannot be read using GetPrivateProfileString() in Win95/98/Me. To get around this, I built an error-checker into my password encryption generator that writes the encrypted password to a test INI file and then tries to read it and decrypt it back again - if it fails, then it tells the user to pick another password. However, this is obviously flawed - because if the password generator is run on a Windows XP or 2000 system, it will never fail - but then when the program is run on Win95/98/Me, the decryption will fail.
So what I need to do is have my password generator check that the encrypted password will work on a Win95/98/Me system even if the generator is being run on an XP/2000 system. I hope I am explaining this okay. Essentially, what I want to do is force the program to act like it is running on a Win95/98/Me system even if it is being run on Windows XP or 2000. Is this possible by doing something like #define _WIN32?
Many thanks,
Keith
|
|
|
|
|
Why don't you convert the encrypted password to something printable before you write it to the INI file e.g. the hex values of each byte and decode it before decrypting. Then you won't have any problems at all.
From someone who uses INI files a lot
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Hi, thanks for the reply. Sorry, but I'm not a very experienced programmer, I don't have a clue how to go about this. If you have any suggestions, I'd be very grateful.
Many thanks,
Keith
|
|
|
|
|
To encode, something like this:
unsigned char* pEncryptedBuf = ...
size_t encryptedBufLen = ...
for ( size_t i=0 ; i < encryptedBufLen , ++i )
printf( "%02X" , (int)pEncryptedBuf[i] ) ;
You probably won't want to print the string to the console but this is the basic idea i.e. the string you store in the INI file is guaranteed to contain only nice characters and won't be a problem on any OS.
Decoding is left as an exercise for the reader...
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Thanks a lot for this, I really appreciate the help. Unfortunately, I am such a novice I am still having problems (sorry). How would I use this code to convert an exising encrypted string (eg. encrypted_password_str) and store it in an INI file? I tried this:
char test_str[MAX_PATH];<br />
char test2_str[MAX_PATH];<br />
<br />
unsigned char* pEncryptedBuf = (unsigned char*)encrypted_password_str;<br />
size_t encryptedBufLen = sizeof(encrypted_password_str);<br />
for ( size_t i=0 ; i < encryptedBufLen; ++i )<br />
{<br />
strncpy(test2_str,"",MAX_PATH);<br />
itoa((int)pEncryptedBuf[i],test2_str,10);<br />
strcat(test_str,test2_str);<br />
WritePrivateProfileString("TestHex","TestHex",test_str,TestFile_str);<br />
}
But this prints odd characters to the INI file too, and I think I have totally screwed this up. Sorry if this looks incredibly stupid or obvious to you.
Many thanks,
Keith
|
|
|
|
|
I think you are trying to solve the wrong problem...
Why not do a base64 encoding of the encrypted password?
"was wir auch tun, wohin wir gehen
die illuminaten sind im system
sie kontrollieren überall
und 23 ist ihre zahl!"
23, welle: erdball
|
|
|
|
|
Hi, thanks for the reply. Sorry but I'm a bit of a C++ hack - ie. I'm a self-taught novice - so I'm not really sure what you mean. I've been doing a search on "base64 encoding" but can't seem to find anything that will help. Presumably this would put it into some form that could be placed in my INI file? If you could give me any advice on how to go about this I'd be really appreciative.
Thanks,
Keith
|
|
|
|
|
|
Why not store the encrypted password as a binary value in the registry?
Dave
|
|
|
|
|
Hi, thanks for the reply. I prefer to use an INI file (I'm using an INI file for all of the other settings anyway) - to be honest I've never really used the registry in my programming anyway, as I'm pretty much a hack - and a novice - when it comes to C++.
Many thanks,
Keith
|
|
|
|
|
GetPrivateProfileString is EVIL. As you have found out, it has severe restrictions on 9X. It won't work at all if your INI file gets bigger than 64K.
It is not that difficult to write your own file routines to read an INI file, line by line, and do whatever you want with it. That's the approach I would use.
You can pick your friends, and you can pick your nose, but you can't pick your friend's nose.
|
|
|
|
|
this is not a soln. to ur problem. infact i'm askin for some help.
i'm also storing the passwords in ini files, but i've no idea how to encrypt and decrypt in my prog.
can u share some code with me
thanx and regards
|
|
|
|
|
Hi,
I am developing an MFC application on VC++ .Net with HTMLHelp generated by the AppWizard. I am looking to have context-sensitive help, much of which was generated by the wizard, but I find I have to add bits regarding menu options or toolbar options I have added on later.
I have invoked the help as follows:
ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
I have included the helpfiles for each option in the HTMLHelp project file alias:
ID_LPS_DELETE = hid_record_delete.htm
I have included their definitions in a header file HTMLDefines.h:
#define ID_LPS_DELETE 32792
I have included the header file in the map section of the project file:
[MAP]
#include HTMLDefines.h
With all of the above I am looking to have the help window come up automatically showing the correct Help page when you drag the Help icon onto a menu option, or press F1while highlighting a menu option. But I just get a message saying "Failed to launch Help".
What am I doing wrong??? All help appreciated,
Trimtrom
|
|
|
|
|
I have derived a class from fstream and my problem is that I can't write after I've read from the file.
My class looks like this:
class CLogBook : public fstream
{
public:
CLogBook();
~CLogBook() { close(); };
void SaveLogData();
void ReadLogData(string&);
int& ErrorCode() { return m_errorCode; };
string& ErrorMessage() { return m_errorMessage; };
string& Extra() { return m_extra; };
private:
string m_errorMessage;
int m_errorCode;
string m_extra;
};
SaveLogData() just formats a string and calls write(...) .
ReadLogData look like this:
void CLogBook::ReadLogData(string& data)
{
data.clear();
seekg(0);
while(!eof())
{
char* temp = new char[1024];
getline(temp, 1024, '\n');
data.append(temp);
data.append("\n");
delete [] temp;
}
}
and my test code looks like this:
CLogBook dummy;
dummy.open("test.txt", ios_base::in | ios_base::out | ios_base::app);
dummy.ErrorCode() = 123;
dummy.ErrorMessage() = "Error occured in your brain.. please RTFM!";
dummy.Extra() = "WinMain";
dummy.SaveLogData();
string buf("");
dummy.ReadLogData(buf);
MessageBox(NULL, buf.c_str(), "", MB_OK);
dummy.ErrorCode() = 666;
dummy.ErrorMessage() = "never written words";
dummy.Extra() = "BASIC SUCKS";
I hope I've got everything here... hope you can help!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I thought an fstream should be closed for reading before you try to write to it. I could be wrong, of course...
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
I tried this:
CLogBook dummy;
dummy.open("test.txt", ios_base::in | ios_base::out | ios_base::app);
dummy.ErrorCode() = 123;
dummy.ErrorMessage() = "erro error error";
dummy.Extra() = "WinMain";
dummy.SaveLogData();
dummy.close();
dummy.open("test.txt", ios_base::in | ios_base::out | ios_base::app);
string buf("");
dummy.ReadLogData(buf);
MessageBox(NULL, buf.c_str(), "", MB_OK);
dummy.ErrorCode() = 666;
dummy.ErrorMessage() = "yadda yadda";
dummy.Extra() = "Linux";
As you can read from the comments, it didn't work...
I must be somewhere else or what have I done wrong.... am I using the fstream wron or what?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Try calling clear() before attempting to write.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
nope...
I've also tried flush() with no success...
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|