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.

Member Avatar for iamthwee

1. c/c++ isn't the best choice of language to read 'n' parse xml.
2. You might need to contruct a tree of some sort to retain the importance of the xml hierarchy -- or use a third party library. I believe the defacto is expat?
3. Your program has elementary bugs that need fixing first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.