Originally Posted by
bernt
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.