| | |
Read from file, delimiter is ;
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 16
Reputation:
Solved Threads: 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?
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?
C++ Syntax (Toggle Plain Text)
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") }
Last edited by AcidG3rm5; Nov 23rd, 2008 at 3:24 am.
![]() |
Similar Threads
- Newbie C++ Search and Parsing Text file. (C++)
- read file with delimiter (C++)
- How to print to file (Perl)
- Reading specific line in a file. / Searching (C++)
- Read In Text help (Java)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
- File parsing in 'C' (C)
Other Threads in the C++ Forum
- Previous Thread: ifstream and eof
- Next Thread: generating an 'infinite' number
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





