(sorry if I duplicate anything mentioned above)
Code:
#include <stdio.h> // standard IO
#include <conio.h> // keyboard-monitor note that conio.h is deprecated in C99 IIRC
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
int n, i; // variables declaring
int x = 0;
char *old_EU[] = {"Austria", "Belgium", "Spain", "Holland", "Ireland", "Italy", "Greece", "Luxembrug", "Portugal",
"France", "Sweden", "Germany", "Finnish", "Great Britain", "Denmark"};
n=sizeof(old_EU)/sizeof(int); // get the number of different countries in array Bad idea. As matsp points out, this won't give the result you're looking for.
char *file="c:\\Import.xml"; // you can use forward slashes when using the C standard library
char rida[240], *pos;// why 240? where does this magic number come from?
FILE *fp;
fp=fopen(file, "r"); // these two lines can be changed to if((fp = fopen(file, "r")) != NULL)
if(fp){ // file opened successfully
while (!feof(fp)){ // as mentioned before, using feof to control a loop is a pretty bad idea. replace this and the next line with while(fgets(rida, sizeof(rida), fp) != EOF)
fgets(rida, sizeof(rida), fp); // duplicated below! there's a way to avoid this . . . there's a reason that you have a do . . . while loop down there . . . even if you are using this to get past the first '<' in the xml file, it's still a bad idea to duplicate code like this. think on it, there *is* a better way.
pos=strtok(rida, "<>");
do{
for (i=0; i<n; i++) {
if (strcmp(old_EU[i], pos) == 0)
x++;
//printf("%d", x);
}
printf("%s\n", pos);
pos=strtok(NULL, "<>");
}while(pos && *pos!='\n');
}
}
else printf
("File %s couldnt be opened\n",
file);
printf("\n%d , % d", x, n); // why x?
printf("\nPress any key...");
getch(); [color=red]// use getchar(), not getch() . . .
return 0;
}
Hope this helps a little.