| | |
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 arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





