dooker
01-10-2004, 03:22 PM
I have written the following 2 functions to try and send and print a menu title from a server to connected clients on a network. When I try and compile the server I get the following errors:
chat_sv.c:300:10: warning: character constant too long
chat_sv.c: In function `send_menu':
chat_sv.c:300: incompatible types in assignment
chat_sv.c:301:10: warning: character constant too long
chat_sv.c:301: incompatible types in assignment
chat_sv.c:302:10: warning: character constant too long
chat_sv.c:302: incompatible types in assignment
I have declared my messages as type char msg[25] and then assigned my message to the variable by msg = 'message'; Can anyone tell me why on compiling I am being told the message type is incompatible and the constant too long??
Thanks
funtion from within server program:
int send_menu(int sockfd, int max_fd)
{
short msg_type;
short msg1_len;
short msg2_len;
short msg3_len;
char msg1[25];
char msg2[25];
char msg3[25];
msg1 = '--------------------';
msg2 = 'LIST OF ONLINE USERS';
msg3 = '--------------------';
msg_type = htons(3);
write(sockfd, &msg_type, sizeof(short));
msg1_len = htons(strlen(msg1));
write(sockfd, (char *)&msg1_len, sizeof(short));
write(sockfd, msg1, strlen(msg1));
msg2_len = htons(strlen(msg2));
write(sockfd, (char *)&msg2_len, sizeof(short));
write(sockfd, msg2, strlen(msg2));
msg3_len = htons(strlen(msg3));
write(sockfd, (char *)&msg3_len, sizeof(short));
write(sockfd, msg3, strlen(msg3));
} /* end of send_menu function */
receiving function from within client code:
int process_menu(int sockfd)
{
int nbytes;
short msg1_len;
short msg2_len;
short msg3_len;
char buf[250];
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg1_len, sizeof(short));
msg1_len = ntohs(msg1_len);
nbytes = read(sockfd, buf, msg1_len);
printf("\t%s\n", buf);
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg2_len, sizeof(short));
msg2_len = ntohs(msg2_len);
nbytes = read(sockfd, buf, msg2_len);
printf("\t%s\n", buf);
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg3_len, sizeof(short));
msg3_len = ntohs(msg3_len);
nbytes = read(sockfd, buf, msg3_len);
printf("\t%s\n", buf);
} /* end of process_menu function */
[/quote]
chat_sv.c:300:10: warning: character constant too long
chat_sv.c: In function `send_menu':
chat_sv.c:300: incompatible types in assignment
chat_sv.c:301:10: warning: character constant too long
chat_sv.c:301: incompatible types in assignment
chat_sv.c:302:10: warning: character constant too long
chat_sv.c:302: incompatible types in assignment
I have declared my messages as type char msg[25] and then assigned my message to the variable by msg = 'message'; Can anyone tell me why on compiling I am being told the message type is incompatible and the constant too long??
Thanks
funtion from within server program:
int send_menu(int sockfd, int max_fd)
{
short msg_type;
short msg1_len;
short msg2_len;
short msg3_len;
char msg1[25];
char msg2[25];
char msg3[25];
msg1 = '--------------------';
msg2 = 'LIST OF ONLINE USERS';
msg3 = '--------------------';
msg_type = htons(3);
write(sockfd, &msg_type, sizeof(short));
msg1_len = htons(strlen(msg1));
write(sockfd, (char *)&msg1_len, sizeof(short));
write(sockfd, msg1, strlen(msg1));
msg2_len = htons(strlen(msg2));
write(sockfd, (char *)&msg2_len, sizeof(short));
write(sockfd, msg2, strlen(msg2));
msg3_len = htons(strlen(msg3));
write(sockfd, (char *)&msg3_len, sizeof(short));
write(sockfd, msg3, strlen(msg3));
} /* end of send_menu function */
receiving function from within client code:
int process_menu(int sockfd)
{
int nbytes;
short msg1_len;
short msg2_len;
short msg3_len;
char buf[250];
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg1_len, sizeof(short));
msg1_len = ntohs(msg1_len);
nbytes = read(sockfd, buf, msg1_len);
printf("\t%s\n", buf);
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg2_len, sizeof(short));
msg2_len = ntohs(msg2_len);
nbytes = read(sockfd, buf, msg2_len);
printf("\t%s\n", buf);
bzero(buf, sizeof(buf));
nbytes = read(sockfd, (char *)&msg3_len, sizeof(short));
msg3_len = ntohs(msg3_len);
nbytes = read(sockfd, buf, msg3_len);
printf("\t%s\n", buf);
} /* end of process_menu function */
[/quote]