problem with comparing tokenised strings with array elements
Code:
#include <stdio.h> // standard IO
#include <conio.h> // keyboard-monitor
#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
char *file="c:\\Import.xml";
char rida[240], *pos;
FILE *fp;
fp=fopen(file, "r");
if(fp){ // file opened successfully
while (!feof(fp)){
fgets(rida, sizeof(rida), fp);
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);
printf("\nPress any key...");
getch();
return 0;
}
It prints all the tokenised strings on separate lines and im assuming that they are stored in pos, but the strcmp never finds a same string ? what is the problem here?
And here is a small cut from my xml file to be clearer
Quote:
<Import partner>
<Country name>Argentina </Country name><Import quantity (kr)> 5670753 </IImport quantity (kr)>
</Import partner>
<Import partner>
<Country name>Aruba </Country name><Import quantity (kr)> 0 </Import quantity (kr)>
<Import partner>
<Import partner>
<Country name>Australia </Country name><Import quantity (kr)> 1263834 </Import quantity (kr)>
<Import partner>
<Import partner>
<Country name>Austria </Country name><Import quantity (kr)> 129511215 </Import quantity (kr)>
</Import partner>