|
I'll do that to double check. Currently, its hacked so that it reads it character by character into a vector (this works 100%) which I then return. I just don't want to read it character by character.
As a side note, after I've read the values in "buffer" in the code it has 4 characters. Sizeof gives me 4. The read and get and getline all break at the \n which is their default delimiter; I'm looking for away to ignore any delimeters and to read the raw byte values.
|
|
|
|
|
when the data is binary, there are no delimiters by default; however you should not use anything that is string-oriented since string methods will react on special characters such as NULL and sometimes NEWLINE.
AFAIK writing a char array to the console in C++ is considered a string operation, so it will stop at the first NULL, interpret every NEWLINE, TAB, etc.
Not sure what sizeof is supposed to do on a char*.
getline for sure is a string operation, not applicable to binary data.
etc. etc.
One advice: fix your reading code until you are completely satisfied, and add error detection code;
do this before you start using your data since now you are building on quicksand and that will keep you doubting everything and hence slow you down.
|
|
|
|
|
Luc Pattyn wrote: when the data is binary, there are no delimiters by default
That's what I thought.
Luc Pattyn wrote: AFAIK writing a char array to the console in C++ is considered a string operation, so it will stop at the first NULL, interpret every NEWLINE, TAB, etc.
That is exactly what I was expecting, so when I was printing it out, I was using cout << hex << buffer[i] << endl; in the loop, but obviously it didn't work. Anyways, I started printing out the data that way to see what was wrong. There is something wrong with the reading and that's why I've hacked it at the moment. I'll be back to it when I have more time.
Luc Pattyn wrote: Not sure what sizeof is supposed to do on a char*.
Gives you the number of bytes and since a char is one byte, it effectively gives you the number of elements in it
|
|
|
|
|
Mustafa Ismail Mustafa wrote: cout << hex << buffer[i] << endl
as buffer is a char*, buffer[i] is a char and gets output as such.
If you want to see its numeric value, you must do something to it, as a minimum cast it to an int.
|
|
|
|
|
Luc Pattyn wrote: f you want to see its numeric value, you must do something to it, as a minimum cast it to an int.
Eh? I will try that as soon as I finish the procedure I'm writing.
|
|
|
|
|
You are reading a binary file, why do you need a delimeter ? Just read whatever number of bytes you need to read and be done with it.
|
|
|
|
|
That's what I was used to but for some reason I cannot understand, every time I hit the \n delimiiter, it breaks the read, and in my particular case, instead of reading 1000 bytes its reading 4, 3 characters + the delimeter.
|
|
|
|
|
Mustafa Ismail Mustafa wrote: When reading a binary file, and you have no clue what the delimeter...
Taken at face value, these two seem to be a bit contradictory.
Mustafa Ismail Mustafa wrote: Is there a single function that can do that...
Do what? Read the entire file into a buffer?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
DavidCrow wrote: Taken at face value, these two seem to be a bit contradictory.
Believe me I know. I'm a bit out of practice with C++, been a couple of years at least and I hit this snag.
DavidCrow wrote: Do what? Read the entire file into a buffer?
Read n number of bytes without being stopped by the delimeter. Any delimeter. And this is the dilemma since binary files should not have a delimeter!
|
|
|
|
|
I've used this function without problem for binary files (MPEG2 TS) before.
|
|
|
|
|
using c++~~~~ from two set like (1,2) and (+,-) how to geneate a list like
[(+1,+2),(-1,+2),(+1,-2),(-1,-2),(+2,+1),(+2,-1),(-2,-1),(-2,+1)]but no(-1,-1)etc.
thanks!
|
|
|
|
|
Have you tried looking at the ADT Set?
|
|
|
|
|
Where can I find the knowledge about ADT set?
And is there any book to recommand?
Thanks ~~~
|
|
|
|
|
Books, I'd recommend "The C++ Standard Library: A tutorial and reference" by Nicolai M. Josuttis.
However, you can find an excellent source about all the Abstract Data Types here: Clickety[^] and here: Clickety[^]
|
|
|
|
|
|
No worries mate
|
|
|
|
|
There's also the standard lib next_permutation(). Or you could write one, basically a cascading swap as you traverse the elems, but I'm sure there are some out there on the web already somewhere.
Any book on combinatorics should have the alg needed.
Applied Combinatorics by Alan Tucker is one.
|
|
|
|
|
Hy,
I have my next problem. I am trying to get an md5 hash from an string (i am using "hello" in this example) The problem is, that the CryptoAPI gives me a different key than the md5 function from PHP.
I think MD5 is MD5 so both should give me the same result.
Here is my Code for the crypto api -> error() only shows Error Nr.: id as a small help for me.
The ByteToStr function is the same ByteToStr function which is in the MSDN.
HCRYPTPROV hProv = NULL;
HCRYPTHASH hHash = NULL;
BYTE *pbKey = (BYTE*)"hello";
DWORD dwKeyLen = strlen((char*)pbKey)+1;
DWORD dwHashLen = 0;
BYTE pbOut[16];
if(!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) Error(1);
if(!CryptCreateHash(hProv,CALG_MD5,0,0,&hHash)) Error(2);
if(!CryptHashData(hHash,pbKey,dwKeyLen,0)) Error(3);
if(!CryptGetHashParam(hHash,HP_HASHVAL,NULL,&dwHashLen,0)) Error(4);
if(!CryptGetHashParam(hHash,HP_HASHVAL,pbOut,&dwHashLen,0)) Error(5);
LPCSTR lpMsg = new char[100];
ByteToStr(dwHashLen,&pbOut,(LPSTR)lpMsg);
MessageBoxA(NULL,lpMsg,"hihi",0);
delete lpMsg;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
Thanks for help.
bye,
gabbana
|
|
|
|
|
gabbana wrote: DWORD dwKeyLen = strlen((char*)pbKey)+1;
Ummmm - is the PHP MD5 algorithm including a NULL terminator byte? Do PHP strings even have NULL terminators? I doubt it very much...
If removing the NULL terminator doesn't fix it, one other thing to consider is whether or not PHP strings are ASCII or some form of multi-byte Unicode?
|
|
|
|
|
wow, Thank you. It was the null terminator.
|
|
|
|
|
Hai!
i have an edit box in which user has to enter only 0x00 to 0xFF,
but if he enters more than two digits i. something like "FF2" or "G2" etc
what is the easiest way to check it!
I need in such a way that suppose user enters a wrong value such as "FF1"
and presses enter then i should display a message "Can enter only between 0x00 to 0xFF " and erase the previous data and set the cusor at the same edit box so that the user can enter a valid value.
I think i can use CEdit::SetLimitText () , so as to make the user to enter only 2 characters but what is the case with "G2" like values?
Thanks !
|
|
|
|
|
|
Use GetWindowText() to get the contents of the edit control. Convert that to an int and compare against 0x00 and 0xff .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi all,
i m using a ListCtrl as Report Type and i want to add button inside the ListCtrl.
please tell me how can i do this.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
here[^] is a link where you can add a combo box. on similar lines you can do this for a button
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|