Hello group,
I am reading an 'mpeg file' from the socket. In read socket I specify
a 'char* buffer' to read the file. However, the content of actual data
contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type
variable. The code looks
like
int len;
char * buf[256];
int size = 256;
string content;
len = read(sockFd, buf, size);
content = buf;
Here if I print buf anything after the '\0' is not printed.
When I copy the buf to content anything after '\0' wipes out and is not
copied. I want full
buffer to be copied to content and later on down the line I want to
save it to a file including
any '\0' characters.
I also want to print the full buffer on the stdout including anything
after '\0' character.
Folks! any suggestion. This bug is stopping my program to proceed.
Thx.
arun 6 1963
* nagrik:
Hello group,
I am reading an 'mpeg file' from the socket. In read socket I specify
a 'char* buffer' to read the file. However, the content of actual data
contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type
variable. The code looks
like
int len;
char * buf[256];
int size = 256;
string content;
len = read(sockFd, buf, size);
content = buf;
string content const( buf, buf + len );
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
* Alf P. Steinbach:
* nagrik:
>Hello group,
I am reading an 'mpeg file' from the socket. In read socket I specify a 'char* buffer' to read the file. However, the content of actual data contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type variable. The code looks like
int len; char * buf[256]; int size = 256; string content;
len = read(sockFd, buf, size);
content = buf;
string content const( buf, buf + len );
Sorry, transposition errors are usually at the letter level, but somehow
here at the word level.
Should be
string const content( buf, buf + len );
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
nagrik wrote:
Hello group,
I am reading an 'mpeg file' from the socket. In read socket I specify
a 'char* buffer' to read the file. However, the content of actual data
contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type
variable. The code looks
like
int len;
char * buf[256];
int size = 256;
string content;
len = read(sockFd, buf, size);
content = buf;
Here if I print buf anything after the '\0' is not printed.
When I copy the buf to content anything after '\0' wipes out and is not
copied. I want full
buffer to be copied to content and later on down the line I want to
save it to a file including
any '\0' characters.
I also want to print the full buffer on the stdout including anything
after '\0' character.
Folks! any suggestion. This bug is stopping my program to proceed.
You don't actually treat the data as a char* type string. The "char*"
is legacy from BSD. Treat it like a void*.
Alf P. Steinbach wrote:
* Alf P. Steinbach:
* nagrik:
Hello group,
I am reading an 'mpeg file' from the socket. In read socket I specify
a 'char* buffer' to read the file. However, the content of actual data
contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type
variable. The code looks
like
int len;
char * buf[256];
int size = 256;
string content;
len = read(sockFd, buf, size);
content = buf;
string content const( buf, buf + len );
Sorry, transposition errors are usually at the letter level, but somehow
here at the word level.
Should be
string const content( buf, buf + len );
Alf,
My content variable is already constructed so after I have buf with me,
the only operation
I am allowed is assignment.
something like
content += buf.
'buf' contains a '\0' character and there will be many more 'buf's I
would like to append to
content. Like
while ( there are more bufs available)
content += buf;
With my implementation, the assignment only copy till the end of '\0'
and later appends
append only after '\0' character and not after the whole buffer, which
I desire. Remember
the '\0' character can occur anywhere in buf and in any buf. I want
content to have full
range of values, including '\0' s.
Too bad C++ does not have a byte type. Any thoughts.
nagrik
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
* nagrik:
Alf P. Steinbach wrote:
>* Alf P. Steinbach:
>>* nagrik:
I am reading an 'mpeg file' from the socket. In read socket I specify a 'char* buffer' to read the file. However, the content of actual data contain '\0' characters at various places.
When I read the full content I copy the char* buffer into a string type variable. The code looks like
int len; char * buf[256]; int size = 256; string content;
len = read(sockFd, buf, size);
content = buf; string content const( buf, buf + len );
Sorry, transposition errors are usually at the letter level, but somehow here at the word level.
Should be
string const content( buf, buf + len );
My content variable is already constructed so after I have buf with me,
the only operation
I am allowed is assignment.
Why don't you just move the declaration?
Or invent a new name?
Or if neither of these options feel right, use the named 'assign' member
function?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
In message <j8********************@newssvr21.news.prodigy.com >, red
floyd <no*****@here.dudewrites
>nagrik wrote:
>Hello group, I am reading an 'mpeg file' from the socket. In read socket I specify a 'char* buffer' to read the file. However, the content of actual data contain '\0' characters at various places. When I read the full content I copy the char* buffer into a string type variable. The code looks like int len; char * buf[256]; int size = 256; string content; len = read(sockFd, buf, size); content = buf; Here if I print buf anything after the '\0' is not printed. When I copy the buf to content anything after '\0' wipes out and is not copied. I want full buffer to be copied to content and later on down the line I want to save it to a file including any '\0' characters. I also want to print the full buffer on the stdout including anything after '\0' character. Folks! any suggestion. This bug is stopping my program to proceed. You don't actually treat the data as a char* type string. The "char*" is legacy from BSD. Treat it like a void*.
He's copying it into a std::string. That takes a char*.
The real problem is that std::string has an assignment operator which
takes a const char * argument, but it stops copying at the first '\0'.
It also has a constructor which takes the same argument and has the same
problem.
The solution is that it also has constructors which take _two_
arguments, either two input iterators or a pointer and a length. Either
of these will copy the appropriate sequence without stopping at '\0':
string content(buf, size); // pointer and count
or
string content(buf, buf+size); // two input iterators
--
Richard Herring This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pikkel |
last post by:
i'm looking for a way to replace special characters with characters
without accents, cedilles, etc.
|
by: quickcur |
last post by:
I am rewrite some of my excel sheets to xml document. In my excel,
there is a lot of special characters like "/", " " (space), "#", "+'.
I am using a java program based on JDom to to create xml....
|
by: Peter Monsson |
last post by:
Hi all,
I'm sitting with a problem where I have some special characters which
have been "stringified" meaning that instead of having f. x. a '\n' or
'\x20' I have "\n" and "\x20" and I have to...
|
by: M Kinnear |
last post by:
I want to check a string only contains a-z 0-9 ( ) . and #
I've used
ereg("^*)$"),$instr)
which parses a string correctly until I try and parse a !,",£,$ ... or any
of the other...
|
by: KevinADC |
last post by:
Purpose
The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |