Mariyam Mohammed Jalil Mariyam Mohammed Jalil - 6 months ago 88
C Question

error invalid conversion from int to const char* [fpermissive] in C

I get this error when i run the following code , on line 21

Error


error invalid conversion from int to const char* [fpermissive]


Code

receive(struct sockaddr_in sockad, struct message m){
int rc;
int i;
int ibuf;
i = sizeof(sockad);
rc = recvfrom(sd,&m,strlen(ibuf),0,(struct sockaddr *)&sockad,(unsigned long)&i ); /* line 21*/
if (rc < 0) {
perror("recvfrom"); exit(1);
}
}


I tried the solutions that in stackoverflow but no luck

Answer Source

The error is caused by strlen(ibuf)... when int ibuf...

You should pass a string to strlen, although you might have intended to use sizeof(m).

You might have also intended to use pointers, as in struct message *m, so that:

void receive(struct sockaddr_in * sockad, struct message * m){
  int rc;
  socklen_t i;
  i = sizeof(*sockad);
  rc = recvfrom(sd, m, sizeof(*m),0, sockad, &i ); /* line 21*/ 
  if (rc < 0) {
    perror("recvfrom"); exit(1);
  }
}