try any one of these , but be prepared to learn lots of COM stuff. This is one case I recommend doing it in VB.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>please tell me by some giving some points...as to what the approach should be....instead of giving google links
The link I posted was incorrect -- see my next post for some good ones.
you really need to learn to do some research on your own. reading xls files isn't a simple task. The file format is a Microsoft secret, subject to change from one version of Excell to another, and requires knowedge of COM because you will be calling some Excell functions to manipulate the file, you don't do it in your program directly because you will not know the file format. If you really want to do that there is information out there that you will need to study. google is the FIRST place you should be looking and maybe a book from www.amazon.com or your local book store.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The link should have been this one. But then you could have easily found that out yourself.
And here are some others about Excel Automation
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Um. I think you got it confused dragon. He is infact looking to read an XML file. So I think your first link is correct.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Um. I think you got it confused dragon. He is infact looking to read an XML file. So I think your first link is correct.
Well, in that case forget what I posted about Excell Automation -- it has nothing to do with XML files. Guess I must be getting senile in my old age:mrgreen:
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Here is an XML file and a C++ program that processes it. XML file structure is user defined. So this won't work for your XML file. But you can get an idea on how to proceed by studing this example. Now you figure how to do it for your XML file on your own.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
This c++ example from boost looks promising. Never used it myself.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
what if each time i need to load a different XML file...say...xyz1 then xyz2 then xyz3 and so on.....i.e open first xml file(xyz1) read it open next(xyz2)....and so on but in a loop so could you tell me how to increment the name of xml file in each loop..i.e xyz1...then xyz2.....which C functions can do this
Thanks
You will have to create the filename by using a function like sprintf or snprintf . snprintf is much safer.
something like
for ( int file_number = 1; file_number<= 3; file_number++ )
{
char filename[ 20 ] = "";
snprintf( filename, 19, "xyz%d.xml", file_number );
printf("%s\n", filename );
// pass filename to your xml file opening function
}
should do the trick.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Thanks a lots...i worked with similar sprintf() function in MATLAB but didnt know similar function exists in C also....
MATLAB is more or less like C, so most functions in MATLAB are available in C.anyways relating to the xml code link that you gave that day.....it was in German(maybe)..so i couldnt understand the comments...
Damned if I knew either. More like Dutch I suppose.... but the initial code in that xml file said for(i=0;i<5;i++) but you corrected it to for(i=0;i<3;i++) and the program wirked ...could you tell me what was the problem with initial code...........Please
Thanks
The line that should be parsed was <Pindala> 83858km² </Pindala><Rahvaarv>8 116 000</Rahvaarv>
So after searching for the Word Pindala , we should stop at the word Rahvaarv , because that is processed in the next part.
if (strcmp(pos, "Rahvaarv") == 0)
That means starting from the word P, how many delimiters should we parse to get to Rahvaarv? <strong><</strong>Pindala<strong>></strong> 83858km² <strong><</strong>/Pindala><Rahvaarv>8 116 000</Rahvaarv>
The answer is 3. The ones in Blue are taken care of by the pos = strtok(rida,"<>"); at the beginning.
So you should have 3 strtoks.
Those 3 are
if (strcmp(pos, "Pindala") == 0)
{
for (i=0;i<3;i++)
{
pos = strtok(NULL,"<>"); // Called 3 times
So that makes 3. If you put 5, it would stop somewhere after Raahvarv and you will not be able to parse the values needed in the next if statement. Anyway I suggest you look at how strtok conducts it's search given in this page . That will make it more clearer.
Also note that I didnt look at the code much at that time; I only wanted to get him going, so even now I can see a lot of cleaning needs to be done in it. For example
if ((pos != NULL)&&(k==0)) does not need the check for k, and i++; can be safely removed from the code. You can clean up the code before you use it. That makes understanding the code much easier. Oh well.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Hello,
I couldnot understand the working of strtok().....does it parse the string in <>.....then how come it displays the names of countries etc. which are not in <>......or it parses only 1 delimiter < at a time......but then why do we write strok(s1,"<>"); .....i followed the link you gave me but i couln ot understand its working so could you throw some light on this topic.......
Thanks
I suggest you try parsing just one line instead of the whole file, and see what are the contents pointed by pos, and the original array step by step by adding some printf statements. Then try to see how that agrees with the explaination given by that site. You will have a better chance of understanding the code that way.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115