Hey guys, i'm back. I'm having troubles now using/understanding the read() function. Again what I have been trying to do is store what the user types in as a char array, until the user types "/send" once "/send" is detected i'll send the char array out. But I'm having troubles understand how to do this (concept is there) code is not.
Here's what I am trying to do
Code:
while( (num = read(0,message,1024)) > 0){
//printf("Num = %d\n", num);
//printf("Message to send: %s\n", message);
//printf("strcmp returns: %d\n", strcmp(message,"exit\n"));
if(strcmp(message, "exit\n") == 0){
printf("Exiting . . .\n");
/* Close this connection. */
pthread_join(root, &temp);
close(sock);
exit(0);
}
printf("Message: %s", message);
if(strcmp(message, "/send\n") == 0){
if(send(sock,buffMessage,sizeof(buffMessage),0) < 0){
pdie("Writing on stream socket");
}
} else {
strcat(buffMessage,message);
printf("buffmessage: %s\n", buffMessage);
}
I initially thought that read() would save everything but again it seems to overwrite all previous inputs. BAHH!