Thread: Organizing a text file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bernt View Post
    Thanks.

    I looked at the ALICE program. They split the patterns into files (A.txt, B.txt...) based on the first letter of the input, to minimize time spent searching.
    Leave it all in one file and then break it up when you load it:
    Code:
    struct whatever *Alist, *Blist...etc
    switch (pattern[0]) {
         case ('a'): addto(Alist, pattern, response)
    Alist would be a pointer to an array of structs, and "addto" would be a function to allocate another struct in the array + add the data to it. I guess these would ideally be linked lists -- maybe that is a bit much to tackle all at once...

    And on the other hand...
    If you are just doing this as a learning exercise, don't waste your time making up tons and tons of patterns/responses -- that is not programming, it's tedious. I think the point you should clue into here is that dealing with data in memory is much much much faster than reading it from a file. You should be able to do the struct array (forget linked lists) -- a basic task. That's learning C programming.
    Last edited by MK27; 05-15-2009 at 02:37 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM