strcmp() not returning 0 when its suppose to
Hi there, I'm writting a programming that takes in words at the commandline and sends it via tcp/ip sockets. I am trying to write an exit case (ie. when user types in "exit" break out of loop and exit closing socket). However I can not get to the exit case. When i type in exit strcmp returns a value of 10 and not zero. I am confused as to why this is. Here is the section of the code that I am currently working on
Code:
while(1){
pthread_create(&root, NULL, Display, (void *) &x);
printf("Inside while loop no.1\n");
while( (num = read(0,message,sizeof(message))) > 0){
printf("Num = %d\n", num);
printf("Message to send: %s\n", message);
printf("strcmp returns: %d\n", strcmp(message,"exit"));
if(strcmp(message, "exit") == 0){
printf("Exitting . . .\n");
}
if(send(sock,message,1024,0) < 0){
pdie("Writing on stream socket");
}
}
pthread_join(root, &temp);
/* Close this connection. */
close(sock);
break;
}
and then output when i type in exit:
Quote:
Inside while loop no.1
THIS IS THE TERM /dev/ttys002 //ignore this
exit
Num = 5
Message to send: exit
strcmp returns: 10