Link to home
Start Free TrialLog in
Avatar of rashmi_be
rashmi_be

asked on

Map file

I have a file which stores values in the following format

filename id path

For example :
..\..\include1 abc\common.h 4223 \ab1 abc\temp
..\..\include2\conhigh.h 4224 \vb12\temp

I would like to know what is the best way to retrieve values from this file .Can i accomplish this using hashmap ?I am looking for actual code ?

Thanks
Avatar of Axter
Axter
Flag of United States of America image

Hi rashmi_be,
You can use INI API functions.
See GetPrivateProfileString

David Maisonave :-)
Cheers!
Avatar of _corey_
_corey_

rashmi_be,

Are the id's unique and do I see multiple path's in the line?

If they are unique (well even if they aren't) you could either use a map or a hash_map to associate the id with the rest of the data.

I'd probably suggest a structure to hold the filename and paths.

typedef struct map_section{
   int id;
  std::string filename;
  std::vector< std::string > paths;
} map_section;

std::map< int, MAP_SECTION > map_file;

corey
Since the filename/path's in the file isn't enclosed in quotes, you just have to create some sort of line parser.

eg. there isn't anything invalidating such entries
..\folder 123\file 1234 path
and there is no standard way to parse this

unless the entries are separated by tab, you infact has a unparsable format
eg.
123 123 123 123

what is what? keep in mind that files and folders can consist of just numbers and there is the possibility of spaces in file and folder names.

I think you have to define your fileformat at bit more precise


hth
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you got a draft there, but it will break if the filename (first path) contain space + backslash ( a bit "kinky", but possible )


I would suggest to separate the fields by tab in the file, and then rework the solution from  itsmeandnobodyelse to just do line.find( '\t', pos )


>>>> if the filename (first path) contain space + backslash

folders with trailings spaces are not valid or better trailing spaces are truncated after folder creation:

     mkdir "test   "
     chdir test

Both statements are valid.

Regards, Alex
rashmi,

a C grade for a 20 points question where you got a full and complete solution is absolutely inacceptable. A C grade is appropriate if you don't get an answer or if experts refuse to explain their comments. I doubt that anybody will answer to your next question. I definitively won't.
B is the new A and C is the new B.  A complete answer only gets a B these days.

It's not even there for a big reason -- people take is so seriously.

corey
This user's grading history is very misleading.
At first glance, it looks like the questioner has a good grading history, but when you look at each question, you'll notice that the only time an A grade has been awarded is when it has been force accepted by a Moderator.

So in reality, not only does this questioner have a bad grading history, but he/she has a bad history of abandoning questions.

The questioner also has a bad history of awarding very low points.