Thread: reading arrays from files

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    reading arrays from files

    As part of a network chat program i am currently writing i want to include a feature to scan messages for "disallowed words". At the moment these are hard coded as alist of arrays hwihc uses strstr to search the text for the words listed.

    However i want to allow the administrator to add and remove words s they need to be stored in a list - how can i store arrays in alist, and read them in for the application to ise. any ideas would be very helpful!
    tia
    Monday - what a way to spend a seventh of your life

  2. #2
    Unregistered
    Guest
    if i understand what you're asking for, you could keep the arrays you currently have, making sure they do not have preset bounds ( ie you want [] ), and when the user adds a new word, just search through the array for a "NULL" value...if it is found, put that word there - if it isn't, then add a new array element with that word. when they choose to remove a word, simply search the array for that word and set that element to NULL.

    is that what you mean?

  3. #3
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    I think so, but ill explain myself alittle clearer.

    I want a list of disallowed words stored in a file, if logged in as admin this list can me modified - (add/remove).
    So when the user enters the text i want to scan the text for any words that featire in the list.

    So i need to store the arrays with the words in a file, the coding i have at the moment looks like this
    ___________________________
    char DisallowedWord1[8]="this";
    char DisallowedWord2[8]="that";
    char text[256];
    cin.getline(text, 256);
    if (strstr(text, DisallowedWord1)!=NUL)
    { cout<<"you cant use that word!";}
    else
    //scan message for next
    _______________________________

    as these are hard coded they cannot be modified by admin, which makes the filter kind of pointless. I want to list these in a text file, i think i can work out how to modify them but i dont know how to read in an array from a file.

    tia
    Monday - what a way to spend a seventh of your life

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading integers into arrays from text files
    By c_beginner in forum C Programming
    Replies: 6
    Last Post: 08-05-2004, 11:42 AM
  2. Issues reading text files
    By ozzy34 in forum C++ Programming
    Replies: 5
    Last Post: 06-01-2004, 08:15 AM
  3. reading structured arrays, changing their structure
    By _kevin007 in forum C Programming
    Replies: 6
    Last Post: 05-15-2003, 03:49 PM
  4. Having some trouble with reading from files
    By bluebob in forum C Programming
    Replies: 19
    Last Post: 04-18-2002, 05:29 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 07:27 AM