ashwini
asked on
length of a string containing binary data
I have a BYTE *str;
In this BYTE string I am storing binary data which may contain many null terminating characters.
Functions like strlen and sysstringlen return the length of the string till the first found null terminating character.
I want to find the entire length of the string.
How do I do that????
NOTE:-
I am not using win32 APIs.
I am using COM language.
In this BYTE string I am storing binary data which may contain many null terminating characters.
Functions like strlen and sysstringlen return the length of the string till the first found null terminating character.
I want to find the entire length of the string.
How do I do that????
NOTE:-
I am not using win32 APIs.
I am using COM language.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If the string data is coming from some other way,say from a dtatabase,then how do I go to the end of the data string and append a EOS character.
The problem is that how do I know that the binary data is ending at a particular position in the string.
The problem is that how do I know that the binary data is ending at a particular position in the string.
ASKER
Can I know how many bytes are dynamically allocated to the BYTE *str in which the binary data is stored????????
no
How do you dynamically allocate BYTE *str?
ASKER
What I want to do is that somehow I want to strore this data coming from a database in a BYTE * variable.For this I first want to know the length of the data coming to me and accordingly strore it in the variable.After this I want to store the length in a different variable and send it to some other method.
ASKER
The data coming to me can be less than or equal to 60000 bytes.
How is the data coming from a database?
ASKER
The data comes through a socket.
If there data is Variable Lenght format, they have standart
structure: Len (usually 2 b), Data (Len baits).
structure: Len (usually 2 b), Data (Len baits).
ASKER
Yes
Sorry, ashwini, what means "Yes"? Is my reply right?
(in this case you must accept reply) or something else?
(in this case you must accept reply) or something else?
ASKER
AlexVirochovsky,
Can you please clarify your answer.
A small piece of code would suffice.
I didn't get what you replied.
Regards
Jasmina
Can you please clarify your answer.
A small piece of code would suffice.
I didn't get what you replied.
Regards
Jasmina
If i uderstand right, you want clarify reply about
Variable Lenght Format?
Well, records of such form can be builded in structure:
Len (2 b usually), text. Can be some variants:
For example, record can be from some fields.
In such case will number of fields,
and in Loop by number of fields : len of field, field.
All this depends of database, that you work with.
Example of code for 2-nd case
....
char *buff; //input buffer
short nNumFields;//number of fields
memcpy(&nNumFields, buff,2);
char *ptr = buff+2;
char *MyString;//result
for (int i = 0; i < nNumFields; i++)
{
short nLen;
memcmp(nLen, ptr,2); ptr += 2;
strncpy(MyString, ptr,nLen);
ptr += nLen;
}
....
I hope(to 50%), that it helps. )-:
Alex
Variable Lenght Format?
Well, records of such form can be builded in structure:
Len (2 b usually), text. Can be some variants:
For example, record can be from some fields.
In such case will number of fields,
and in Loop by number of fields : len of field, field.
All this depends of database, that you work with.
Example of code for 2-nd case
....
char *buff; //input buffer
short nNumFields;//number of fields
memcpy(&nNumFields, buff,2);
char *ptr = buff+2;
char *MyString;//result
for (int i = 0; i < nNumFields; i++)
{
short nLen;
memcmp(nLen, ptr,2); ptr += 2;
strncpy(MyString, ptr,nLen);
ptr += nLen;
}
....
I hope(to 50%), that it helps. )-:
Alex
ASKER