[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

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.
0
ashwini
Asked:
ashwini
  • 8
  • 4
  • 2
  • +1
1 Solution
 
ashwiniAuthor Commented:
Edited text of question.
0
 
AlexVirochovskyCommented:
0x0 is standart end of string. But becouse you  string contains many string(array of strings), you must set
some symbol/symbols as you oun end of string;
For example: say  EOS = '\n'
In this case you can use code:
for (int len = 0;  str[len] != EOS; len++);
In end len-> you lenght of string
0
 
ashwiniAuthor Commented:
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ashwiniAuthor Commented:
Can I know how many bytes are dynamically allocated to the BYTE *str in which the binary data is stored????????
0
 
alexoCommented:
no
0
 
ozoCommented:
How do you dynamically allocate BYTE *str?
0
 
ashwiniAuthor Commented:
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.


0
 
ashwiniAuthor Commented:
The data coming to me can be less than or equal to 60000 bytes.
0
 
ozoCommented:
How is the data coming from a database?
0
 
ashwiniAuthor Commented:
The data comes through a socket.
0
 
AlexVirochovskyCommented:
If there data is Variable Lenght format, they have standart
structure: Len (usually 2 b), Data (Len baits).
0
 
ashwiniAuthor Commented:
Yes
0
 
AlexVirochovskyCommented:
Sorry, ashwini, what means "Yes"? Is my reply right?
(in this case you must accept reply) or something else?
0
 
ashwiniAuthor Commented:
AlexVirochovsky,

Can you please clarify your answer.
A small piece of code would suffice.

I didn't get what you replied.

Regards
Jasmina
0
 
AlexVirochovskyCommented:
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
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 8
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now