Simple scanning in an input with whitespaces except I can't figure out why the code is enter my 'if' statement when i don't input anything. Can anyone see the problem?
Code
Code:
while(exitStatus != 0){
printf("Say(0 to exit): ");
//scanf("%s", &message);
int inc = 0;
while((ch = getchar()) != '\n')
{
message[inc++] = ch;}
message[inc] = '\0';
inc = 0;
while(message[inc] != '\0'){
putchar(message[inc++]);}
//printf("\n");
if(strcmp(message, "0") == 0){
exitStatus = 0;
printf("Exiting", exitStatus);
break;
}else{
char *ptr = message;
send(sockfd,ptr,strlen(message),0);
printf("Sent '%s' to server.\n",message);
}
}
and the output is:
Say(0 to exit):
Sent '' to server.
Say(0 to exit):
I don't know where the " '' " is coming from since nothing is getting passed in. Thanks.