I got it working with strncmp. I have one more quick noob question though.
I want the server to validate the user input so if there is more than one character in echoString the message "message too big" is displayed. I've got to code bellow to display a message if a letter is input however if a number greater to 9 such as 10, 21 it would display 1 or 2 respectively. Its just using the if statements to its textual value and ignoring the if statement to detect its size.
echoBuffer is defined at 32 bits long. I'm 99% sure strlen will only pick up the length of characters entered by the user in echoBuffer[32] as if it isnt present in the send socket, only one character is sent instead of several.
I've tried it as length == 1.
Code:
int length = strlen(echoBuffer);
if(length != 1)
{
if(strncmp(echoBuffer, "1", 1) == 0)
{
strcpy(echoBuffer, "One ");
}
else if(strncmp(echoBuffer, "2", 1) == 0)
{
strcpy(echoBuffer, "Two ");
}
else if(strncmp(echoBuffer, "3", 1) == 0)
{
strcpy(echoBuffer, "Three ");
}
else if(strncmp(echoBuffer, "4", 1) == 0)
{
strcpy(echoBuffer, "Four ");
}
else if(strncmp(echoBuffer, "5", 1) == 0)
{
strcpy(echoBuffer, "Five ");
}
else if(strncmp(echoBuffer, "6", 1) == 0)
{
strcpy(echoBuffer, "Six ");
}
else if(strncmp(echoBuffer, "7", 1) == 0)
{
strcpy(echoBuffer, "Seven ");
}
else if(strncmp(echoBuffer, "8", 1) == 0)
{
strcpy(echoBuffer, "Eight ");
}
else if(strncmp(echoBuffer, "9", 1) == 0)
{
strcpy(echoBuffer, "Nine ");
}
else
{
strcpy(echoBuffer, "300 ");
}
}
else
{
strcpy(echoBuffer, "Message too big");
}
recvMsgSize = strlen(echoBuffer);
Thanks for any tips. I'm working from tcp/ip sockets and c/the c programming language books to do this.