473,472 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Byte Array in C

I want to Transmit Data using Using Socket Programming in C. The only
Problem is that the data contains a lot of NULL characters in between
(it is an JPEG image data).so if I populate a Char array with the data
and try transmitting using send() only a part of the data is sent,
since null character is taken as a end-of-line in C.
Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.

Nov 15 '05 #1
6 13669
<pr***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I want to Transmit Data using Using Socket Programming in C. The only
Problem is that the data contains a lot of NULL characters in between
(it is an JPEG image data).so if I populate a Char array with the data
and try transmitting using send() only a part of the data is sent,
since null character is taken as a end-of-line in C.


'\0' is not "taken as end-of-line in C". The string functions use it to
indicate the end of a string.

There are no sockets and no send() function in standard C. However, if you
read the documentation for your system's send() function I am sure you will
find no mention of any significance of characters with the any particular
values.

For help with socket programming you should ask in a platform-specific
newsgroup.

Alex
Nov 15 '05 #2
On 14 Jul 2005 02:40:09 -0700, pr***********@gmail.com
<pr***********@gmail.com> wrote:
I want to Transmit Data using Using Socket Programming in C. The only
Problem is that the data contains a lot of NULL characters in between
(it is an JPEG image data).so if I populate a Char array with the data
and try transmitting using send() only a part of the data is sent,
since null character is taken as a end-of-line in C.
Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.


(a) Sockets are not part of the C standard, and are therefore off topic
in comp.lang.c, try a newsgroup relevant to your operating system,
for example:

comp.unix.programmer
comp.os.linux.networking
comp.os.ms-windows.apps.winsock.misc
comp.os.ms-windows.networking.tcp-ip

(b) A null character is not "taken as a end-of-line in C", the end of
line character is '\n'. A null character is use to indicate the end
of a string by the string functions and is otherwise treated as
data.

(c) [OFF TOPIC]
The send() function in Unix (and as far as I know Windows Sockets)
sends as many characters as its parameter specifies, it doesn't
handle null characters (or any other character value) specially.
Perhaps you are trying to use strlen() to determine the length? Or
perhaps the receiving program is treating the received data as a
string?
[/OFF TOPIC]

Chris C
Nov 15 '05 #3
> Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.


Keep the length in a variable and try write() from unistd.h (on
POSIX-compatible systems)

Stephan

--
Stephan Beyer, PGP 0xFCC5040F, IRC sbeyer (seebyr, bseyer)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC1nWVbt3SB/zFBA8RArVGAJ9kuz5TPDCcV2bfF2qq8o6w7YvyTgCeKuOR
bRG27vp78fjZkOGtjVuIiW4=
=D3h6
-----END PGP SIGNATURE-----

Nov 15 '05 #4
pr***********@gmail.com wrote on 14/07/05 :
I want to Transmit Data using Using Socket Programming in C. The only
Problem is that the data contains a lot of NULL characters in between
Of course, you meant 'nul characters'...
(it is an JPEG image data).so if I populate a Char array with the data
'Char' is not a standard C type. You meant 'char'...
and try transmitting using send() only a part of the data is sent,
since null character is taken as a end-of-line in C.
What ? I guess that BSD-socket send() function (which is not part of
the C-language) has an address/ length interface. If it's true, the
zeros are just like another data. If not, use another function
(sendto() etc. read the manual).

BTW, there is no relationship between the nul character 0 and the end
of line.
Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.


I'm quite sure it does. You must have some problem before... (like
using strcpy() instead of memcpy() for binary streams...

BTW, the stream should be implemented by an array of unsigned char.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair

Nov 15 '05 #5
Stephan Beyer <s-*****@gmx.net> writes:
Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.


Keep the length in a variable and try write() from unistd.h (on
POSIX-compatible systems)


Neither send() or write() is topical here, since they're both
non-standard functions. Having said that, several others have pointed
out that send() does not treat null characters specially.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #6
pr***********@gmail.com wrote:
# I want to Transmit Data using Using Socket Programming in C. The only
# Problem is that the data contains a lot of NULL characters in between
# (it is an JPEG image data).so if I populate a Char array with the data
# and try transmitting using send() only a part of the data is sent,
# since null character is taken as a end-of-line in C.
# Is there any way that send() can ignore the null character and transmit
# the entire data in the buffer.

Use a write function that includes an explicit data length, like stdio
fwrite or unix write, instead of write function that looks for terminating
byte like fputs.

A unix send(2) function has a buffer size argument. Are you using strlen
to decide the current buffer size or are keeping track of how much you
put in?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Quit killing people. That's high profile.
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
5
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.