Hi i am pretty new to socket programming and I've written a simple client/server system to send data over a socket. I've gotten it working so that I can send a string to the server and receive a reply.
Now I am trying to get the server to recognize command being sent from the client, but everything I send from the client has a newline character on the end. I know I can handle this from the server side, but is there a way to remove the newline character from the client side?
Here is the code which does the writing:
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
buffer[strlen(buffer) - 1] = '\0';
I guess the latter is better than using a memset. memset would be the way to go if OP was dealing with bitmaps or large buffers and structures. – Leatherjacketfgets
expects the buffer size, so make it256
, or even better,fgets(buffer, sizeof buffer, stdin)
ifbuffer
is an array. – Shoup