Sn1P I daXa
New Member
\[code\]#include<stdio.h>#include<stdlib.h>#include<dirent.h>#include<string.h>int main(){ FILE *fin,*fout; char dest[80]="/home/vivs/InexCorpusText/"; char file[30]; DIR *dir; char c,state='1'; int len; struct dirent *ent; if((dir=opendir("/home/vivs/InexCorpus"))!=NULL) { while((ent=readdir(dir))!=NULL) { if(strcmp(ent->d_name,".") && strcmp(ent->d_name,"..") && strcmp(ent->d_name,".directory")) { len=strlen(ent->d_name); strcpy(file,ent->d_name); file[len-3]=file[len-1]='t'; file[len-2]='x'; //strcat(source,ent->d_name); strcat(dest,file); printf("%s\t%s\n",ent->d_name,dest); fin=fopen(ent->d_name,"r"); fout=fopen(dest,"w"); while((c=fgetc(fin))!=EOF) { if(c=='<') { fputc(' ',fout); state='0'; } else if(c=='>') state='1'; else if(state=='1') { if(c!='\n') fputc(c,fout); if(c=='.') { c=fgetc(fin); if(c==' '||c=='\n'||c=='<') { fputc('\n',fout); ungetc(c,fin); } else fputc(c,fout); } } } } close(fin); close(fout); strcpy(dest,"/home/vivs/InexCorpusText/"); } closedir(dir); } else { printf("Error in opening directory\n"); } return 0;}\[/code\]I was trying to convert xml files to text. This code simply remove tags and nothing else.When i execute this code for around 300 files, it doesn't show any error but when number goes to 500 or more i receive a segmentation fault after processing around 300 files.