473,395 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

variable Bytes question

hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalProject\Battleship\NewGame.h(180): error C2691: 'unsigned char
__gc *' : invalid type for __gc array element
x:\User\FinalProject\Battleship\NewGame.h(180): error C2061: syntax error :
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the other
connected socket? thanks

--
-iwdu15
Jan 9 '06 #1
5 1140
this will give you a simple array of bytes.

Byte test[] = new Byte[1];
Byte test2 = 'A';

test[0] = test2;
kind regards,
Bruno.
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:E7**********************************@microsof t.com...
hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalProject\Battleship\NewGame.h(180): error C2691: 'unsigned
char
__gc *' : invalid type for __gc array element
x:\User\FinalProject\Battleship\NewGame.h(180): error C2061: syntax error
:
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the
other
connected socket? thanks

--
-iwdu15

Jan 9 '06 #2
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15
Jan 10 '06 #3
iwdu15 wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?


100 bytes? Bruno's example was a one byte array. But anyway, the trick
to not overflowing an array is to not read more bytes than can fit in it.

doug
Jan 10 '06 #4
if possible, always work with a fixed buffer size.
this will be more performant than always allocating and de-allocating buffers.

i don't know what you intend to send, but if it is not too much, just
allocate an array that will always be big enough. use a 1 MB buffer if that
solves you problem.
IMO that is a much better solution than having to manage variable length
buffers.

having to add xxx lines of memory management code to save a few bytes of
data is not worth it in most cases.
but in all cases, check the array size before you write data to it.

kind regards,
Bruno.

"iwdu15" wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15

Jan 10 '06 #5
ok, thanks alot
--
-iwdu15
Jan 11 '06 #6

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

Similar topics

3
by: Anoop | last post by:
Hi guys i have a piece of code main() { switch(...) { case 1: {
6
by: Prawit Chaivong | last post by:
Hi All I don't know whether I should post this thing to compiler group or this group. Anyway, I decided to post to this group. (I'm sorry if you think I post in wrong group) My question is......
8
by: Groups User | last post by:
C allows type casting in which a variable is converted from one type to another. Does C (whatever standard) allow the type of a variable to change, within a statement, avoiding the conversion?...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
1
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be...
20
by: Manuel | last post by:
hi, I have a problem, a stupid problem. I can't declare a variable of type byte. The g++ said that i have syntactic error in this line. The code is this: byte * variable; well, i think...
29
by: Martin | last post by:
For reasons I won't go into, I need to transfer from 1 to 3 bytes to a variable that I know is 4 bytes long. Bytes not written to in the 4-byte target variable must be zero. Is the following use of...
3
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given...
11
by: EricGoogle | last post by:
Hello All, I am trying to figure out a how to get a variable's name from code. Ex: var MYVAR = 3; alert( ????? ); OUTPUT: "MYVAR"
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.