I am developing an interactive client and server system which can response to a typical Human's Interaction. This program is run in unix enviornment.
There's a Q&A text file stored, in this format.
[Question];[Reply]
How old are you?;I Am 1 year old.
basically the delimiter is a ';'.
Is there any function in c i can call to make some checking?
When the client side sends a query "How old are you" to the server, server is suppose to reply "I am 1 year old"
I know i could use strtok to use ';' as my delimiter. But how do i extract out the answer "I am 1 year old" if it matches?
void reply(int sock)
{
int n, i; //declare variables
char buffer[256]; //to store input from client
//get message from client
bzero(buffer,256);
n = read(sock,buffer,255);
//prompt error if cannot read
if (n < 0) error("ERROR reading from socket");
//change all char to lower
for(i=0; buffer[i]; i++)
buffer[i]=tolower(buffer[i]);
//Need to check the text file here. to get a reply.
// If nothing matches, reply with "Sorry i do not have the answer."
//send message back to client
n = write(sock, buffer, 18);
if (n < 0) error("ERROR writing to socket")
}