Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using winsock send function

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hello,

I am trying to send a unsigned long using the send function defined in winsock

that is,

if (send(sockfd, pCatCode, MAXDATASIZE, 0) == -1)
{
printf("Unable to send data\n");
}

pCatCode is a unsigned long but i get the following compile error

cannot convert parameter 2 from 'unsigned long' to 'const char *'

any suggestions
many thanks
 
> pCatCode is a unsigned long but i get the following compile error
So why does it have a 'hungarian' p at the start of the name, fooling you into thinking it may be a pointer?

My guess is that it should be
Code:
n = send(sockfd, &CatCode, sizeof(CatCode), 0);
if ( n == -1 ) {
  printf("Unable to send data\n");
}
if ( n != sizeof(CatCode) ) {
  printf("Incomplete send, sent only %d\n", n);
}



--
 
It's more safety (honestly;) to use an explicit cast:
Code:
(const char*)&CatCode...
.
C (and C++) can't implicitly convert (unsigned long*) to (char*)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top