Hi, as newbie in c, i have some problems with my code.
I don't know how to read data from into array,
and second, how i can compare data in array?
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main (void){
int i;
char line [240], *pos;
char name[1000];
FILE *fp;
char myfile[20]="names.xml";
fp=fopen(myfile, "r");
if (!fp){printf("Can't open file..\n", myfile);
getch(); return 1; }
while (!feof(fp)){
fgets(line, sizeof(line), fp);
pos = strtok (line, "<>");
if (strcmp(pos, "Name") == 0){
for (i=0;i<3;i++){
pos = strtok(NULL,"<>");
if ((pos != NULL)&&(i==0)){
sscanf(pos, &name[i]); //can't read into array
printf("%s\n", pos); // for pos test
}
}
}
}
fclose(fp);
//for testing array
// for (i=0;i<6;i++) //without this line gives <null>
{printf("\n%s", name[i]);}
printf("\nPress any key..");
getch();
return 0;
}
Thanks for any help.