Thread: File I/O with a twist....

  1. #1
    Registered User blackwyvern's Avatar
    Join Date
    Jan 2002
    Posts
    60

    Question File I/O with a twist....

    Ok, let me describe what I have so far and what I want my program to ultimately do. What I have right now is a very rudimentary and hardwired chatbot. This phase of the project has been completed for 3 months now and my interests were drawn into other areas of interests. I am a beginner to intermediate programmer, but I am been at it for 3-4 years off and on.
    Now, what I want my program to be able to do at this point is to record conversations and be able build responses to certain statements and questions based on the conversations of others or maybe even the chatbots conversation with you. Lets start this off with a sample...
    Chatbot: Hi
    Human: Hello
    //and say that the program only knows Hi as a form of salutation... it may then ask this
    Chatbot: What does hello mean?
    Human: Hello means Hi.
    Chatbot: Ok, so hello then =)



    Now, this is a very simple example of what I want it to do and I want everything stored in a .txt file in the same directory as the program.. I know how to create the file and append info to it and all, but what I am unsure of is how to read information back on a line per line basis
    The text file would look something like this
    1. Hi
    2. Hello
    3. What does hell mean?
    4. Hello means Hi.
    5. Ok, so hello then. =)



    to read line 2 into the program as a string? without reading line 1 and the others? This is the question I would most liked answered... With just this answered I can work around with just this and create something I will be comfortable with, or maybe find better methods out.


    I do appreciate any and all time and thought you put into your responses. Thanks in advance.

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    A chat-bot? Cool. Does this chat-bot work as a stand-alone app or does it work with something like MSN?

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>>to read line 2 into the program as a string? without reading line 1 and the others?
    You can use getline() to grab lines of data from a file.
    You can't skip over lines easily, it's best to read them into a temp buffer, simply ignoring the lines you don't want.
    If you're using binary IO, you can seek to specific points in the file, but you need to know where each line starts/ends, and this will only really work if each line is the same length.

    I presume your text file is like a config file? If it is, you'll probably be able to read it into memory at the start of the program, then you only have to process the list in memory, which you can access a lot easier.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM