0

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")


}
2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by AcidG3rm5
0

i've read about that. actualyl am trying to get getline(a,b,';').

Any moderators around? Can help to shift this thread to c instead? Realised that i posted in the wrong section as i'm doing this program in c

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.