Solved

char* array

Posted on 2006-06-25
6
362 Views
Last Modified: 2010-04-24
I have this code

char             DataPacket[128];
SocketObject ClientSocketObject;

iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0);

and, Recv is defined as,

int SocketObject::Recv( char *szBuffer, int iBufLen, int iFlags)
{
...
}


I'm using Visual Studio.Net 2005,

and when i compile,
i get this error

error C2664: 'SocketObject::Recv' : cannot convert parameter 1 from 'char (*__w64 )[128]' to 'char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


However, this error goes away if i do,

iBytesReceived = ClientSocketObject.Recv(&DataPacket[0], 128, 0);  isntead of
iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0);

and I was wondering if this is the correct way to solve the error. Any explnation will be appreciated. I belive this error does not occur in the old Visual C++ compilers.

Thank you very much
0
Comment
Question by:wonjun
6 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 125 total points
ID: 16980648
iBytesReceived = ClientSocketObject.Recv(DataPacket, 128, 0);

DataPacket should be a pointer to your array of chars.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 16987887
clockwatcher is correct...

If you have an array...
     char   DataPacket[128];
then...
    DataPacket[0] is a single char (the first one in the array)
    &DataPacket[0] is a pointer to a char (char*)
         (the same as.... )
    DataPacket is a pointer to char (char*)
         (however...)
    &DataPacket is a pointer to that pointer (it's a char**)

The prototype requires a pointer-to-char, so either of these will work:
    &DataPacket[0]
    DataPacket

0
 

Expert Comment

by:patti_nyl
ID: 16992050
Hi!

Remove the & sign!

will result to this
iBytesReceived = ClientSocketObject.Recv(DataPacket, 128, 0);


Patrik
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

808 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