| | |
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
Views: 1588 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





