Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

length of a string containing binary data

Posted on 1999-07-23
15
Medium Priority
?
248 Views
Last Modified: 2010-04-02
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
Comment
Question by:ashwini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
  • +1
15 Comments
 

Author Comment

by:ashwini
ID: 1200950
Edited text of question.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 total points
ID: 1200951
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
 

Author Comment

by:ashwini
ID: 1200952
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ashwini
ID: 1200953
Can I know how many bytes are dynamically allocated to the BYTE *str in which the binary data is stored????????
0
 
LVL 11

Expert Comment

by:alexo
ID: 1200954
no
0
 
LVL 84

Expert Comment

by:ozo
ID: 1200955
How do you dynamically allocate BYTE *str?
0
 

Author Comment

by:ashwini
ID: 1200956
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
 

Author Comment

by:ashwini
ID: 1200957
The data coming to me can be less than or equal to 60000 bytes.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1200958
How is the data coming from a database?
0
 

Author Comment

by:ashwini
ID: 1200959
The data comes through a socket.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1200960
If there data is Variable Lenght format, they have standart
structure: Len (usually 2 b), Data (Len baits).
0
 

Author Comment

by:ashwini
ID: 1200961
Yes
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1200962
Sorry, ashwini, what means "Yes"? Is my reply right?
(in this case you must accept reply) or something else?
0
 

Author Comment

by:ashwini
ID: 1200963
AlexVirochovsky,

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

I didn't get what you replied.

Regards
Jasmina
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1200964
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question