#include #include #include #define ROZ 100 /*=================================================================================================*/ typedef struct Wezel { char *zaw; struct Wezel *lista, *prawy; struct Wezel *korzen; }*wezel; /*=================================================================================================*/ wezel inic_wezel(FILE *xml, wezel galaz, wezel root) { char c,tmp[ROZ]; int k,i=0; wezel temp; galaz=malloc(sizeof(wezel)); do { c=fgetc(xml); tmp[i++]=c; if(c<0) break; } while((c!='<')&&(c!='>')); tmp[i-1]='\0'; galaz->zaw=malloc(strlen(tmp)+1); strcpy(galaz->zaw,tmp); galaz->prawy=NULL; galaz->korzen=root; galaz->lista=NULL; if(c=='<') //printf(" [->] "); galaz->prawy=inic_wezel(xml,galaz->prawy,galaz); else return galaz; //printf(" [<-] "); galaz->lista=inic_wezel(xml,galaz->lista,galaz); return galaz; } /*=================================================================================================*/ wyswietl(wezel galaz, FILE *out, int tag, int edyt) { char c; while(galaz) { fprintf(out,"%s",galaz->zaw); if(galaz->prawy) { if(tag) fprintf(out,"<"); wyswietl(galaz->prawy,out,tag,edyt); if(tag) fprintf(out,">"); } galaz=galaz->lista; } } /*=================================================================================================*/ main() { FILE *xml=fopen("xml.txt","r"); FILE *xml_out=fopen("xml_out.txt","w"); wezel root; root=malloc(sizeof(wezel)); root->prawy=NULL; root->korzen=NULL; root->lista=inic_wezel(xml,root->lista,root); wyswietl(root->lista, stdout, 0, 0); printf("\n________________________________________________\n"); wyswietl(root->lista, stdout, 0, 1); wyswietl(root->lista, xml_out, 1, 0); printf("\n________________________________________________\n"); fclose(stdout); fclose(xml); getch(); }