how should i store these?

This is a discussion on how should i store these? within the C++ Programming forums, part of the General Programming Boards category; ok, I have a series of numbers, they happen to be index numbers for files, but anyhow, I need to ...

  1. #1
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001

    how should i store these?

    ok,
    I have a series of numbers, they happen to be index numbers for files, but anyhow, I need to store them in an organized manner, then use the "number" i have stored in conjunction with a filepath string so that i can open these files and search through them, i know how to get them opened up and searched, but how should i store them? here's what i've been tinkering with:
    Code:
    string amt[](
    "0012",
    "0100",
    "0740",
    "3390",
    "4619",
    "4620"
    );
    integer arrays won't work because there are 9's in some of the numbers and i get base 8 errors. i was goofing around and switched to char arrays and got twice the amount of errors i have now...what should i do? I need to organize these things so i can easily pull them out.
    note: in total....there's around 5000 sets up numbers in seperate arrays

    I'm also doing this (i know it's not the right way to do it, but it's a start and i'm hoping you can help:
    Code:
    switch (company) {
    case 0:
    	theArray="amt";
    	break;
    case 1:
    	theArray="barber";
    	break;
    ...
    
    //Then something along these lines (i know this won't work)
    	ifstream file;
    	for(int x = 0;x < theArray.GetSize();x++)
    	{
    	   file.open(theArray[x]);
      ....................
    	 file.clear();
    	 file.close();
    	}
    what can i do here?
    Last edited by Waldo2k2; 07-10-2002 at 01:39 PM.
    PHP and XML
    Let's talk about SAX

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Have you tried a pointer to an array of strings?

    char *strings[] = { "01234", "43210", "4567" };

    Something like that perhaps? You can put a NULL string at the end if it makes some of your algorithms more efficient.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Note quite sure what you mean. But a suggestion: use a table like this:

    Code:
    typedef struct
    {
        char *file_index;
        char *path;
    } file_index_table_s;
    
    file_index_table_s file_index_table [] =
        {{"0000", "c:\aaa"},
         {"0001", "c:\bbb"}};
    Now you can easily lookup the number and if you have the number, then you also have the filepath.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    integer arrays won't work because there are 9's in some of the numbers and i get base 8 errors.
    You mean because of the 0012, 0100, 0740 values? Just don't put the 0's in front of them. Store 12, 100, 740 and when it comes time to use them just remember that they are suppossed to be treated as 4 digit 0 filled values.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >integer arrays won't work because there are 9's in some of the numbers and i get base 8 errors

    Do your file indices have to have four digits? Have you considered something like one of the standard associative containers if you're not using consecutive indices -

    Code:
    #include <map>
    #include <string>
    #include <iostream>
    
    int main(void)
    {
    	std::map<int,std::string> files;
    
    	files[12] = "filename1";
    	files[109] = "filename2";
    
    	std::cout << files[109];
    
      return 0;
    }

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    17

    base 8 problem

    If you are in fact getting an error because of base 8 then you just have to specify decimal in your code. IE:

    NOT:
    Code:
    cin>>number;
    But Instead:
    Code:
    cin>>dec>>number;

  7. #7
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    basically,
    the program goes through a bunch of text files that are actually source code programs for machines such as lathes and the like, the numbers are the filenames (no extensions) and they're spit out by the machine, my program is designed to allow a user to search for a string that user typed within those files, that's why i have to open them. i can't change their names....i like the struct idea, i might try and go with that, but it will be a lot of copy and pasting as there are a lot of numbers.....there's 24 directories, all containing files like these...that might help you guys get a better idea of what i'm trying to do
    PHP and XML
    Let's talk about SAX

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    Do you really need the filenames at compile time? Most operating systems have a function or two to obtain a directory listing at runtime.

    You could get the operating system to provide the filenames in turn and then open and search each one before moving onto the next. What o/s are you using?

  9. #9
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    it's funny that you should mention that, it was my first approach
    but, it was too clunky to strip the directory paths out of the txt files, especially because it also listed c:\.. and c:\... which are just paths to the previous folder...anyhow i also have another way of doing it with some windows functions....and it's sound code and i didn't have to use all the filenames, but for some reason i couldn't get it to give me any information....i'm using this way because once i get over this hurdle i should be able to get it to work.......but i did like my windows function approach as opposed to this...you might see a question tomorrow pertaining to it if i just get sick of this. by the way it's just going to run on win9x, it's a dos console program
    PHP and XML
    Let's talk about SAX

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  2. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 01:27 PM
  3. store data from ifstream and store in link list
    By peter_hii in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2006, 08:50 AM
  4. Do you store store one off data arrays in a class?
    By blood.angel in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2002, 12:05 PM
  5. how to store a node on hard disk
    By ALLRIGHT in forum C Programming
    Replies: 3
    Last Post: 05-13-2002, 10:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21