A
Abhijit
Hello everybody,
I am getting a "segmentation fault" error when i compile the following
piece of code. The program runs fine till it encounters the line of
code saying" FILE_lic=fopen.........". And after that, it terminates
saying segmentation fault. I had included the appropriate header files
also! I couldn't makeout where the problem exists in the program. Can
anyone solve this mistery!
void LICENSEinfo::find()
{
char check[10],vendor[20],date[12];
char uw1[20],uw2[20],mystring[200];
int lic_num;
char filestring[20];
struct dirent *dp, *subdp;
DIR *dir, *subdir;
FILE *FILE_list;
FILE *FILE_lic;
FILE_list = fopen("/tmp/list","w");
// Make "/parent" as the present working directory
chdir ("/parent");
dir=opendir(".");
while ((dp=readdir(dir))!=NULL)
{
if(!strcmp(dp->d_name,".")||!strcmp(dp->d_name,".."))
continue;
subdir=opendir(dp->d_name);
while ((subdp=readdir(subdir))!=NULL)
{
if(!strcmp(subdp->d_name,".")||!strcmp(subdp->d_name,".."))
continue;
if(strstr(subdp->d_name,"_lic")!=0)
{
// read the entire file
strcpy(filestring,subdp->d_name);
FILE_lic = fopen(filestring,"r");
// problem: FILE_lic is reset to 0x0 here.
while (feof(FILE_lic)==0)
{
fgets(mystring,200,FILE_lic);
if((strstr(mystring,"INCREMENT"))||(strstr(mystring,"FEATURE")))
{
sscanf(mystring,"%s%s%s%s%s%d",check,uw1,vendor,uw2,date,&lic_num);
fprintf (FILE_list,"%s \t %s \t %d \n",vendor,date,lic_num);
}
}
}
}
}
}
Thanks in advance
I am getting a "segmentation fault" error when i compile the following
piece of code. The program runs fine till it encounters the line of
code saying" FILE_lic=fopen.........". And after that, it terminates
saying segmentation fault. I had included the appropriate header files
also! I couldn't makeout where the problem exists in the program. Can
anyone solve this mistery!
void LICENSEinfo::find()
{
char check[10],vendor[20],date[12];
char uw1[20],uw2[20],mystring[200];
int lic_num;
char filestring[20];
struct dirent *dp, *subdp;
DIR *dir, *subdir;
FILE *FILE_list;
FILE *FILE_lic;
FILE_list = fopen("/tmp/list","w");
// Make "/parent" as the present working directory
chdir ("/parent");
dir=opendir(".");
while ((dp=readdir(dir))!=NULL)
{
if(!strcmp(dp->d_name,".")||!strcmp(dp->d_name,".."))
continue;
subdir=opendir(dp->d_name);
while ((subdp=readdir(subdir))!=NULL)
{
if(!strcmp(subdp->d_name,".")||!strcmp(subdp->d_name,".."))
continue;
if(strstr(subdp->d_name,"_lic")!=0)
{
// read the entire file
strcpy(filestring,subdp->d_name);
FILE_lic = fopen(filestring,"r");
// problem: FILE_lic is reset to 0x0 here.
while (feof(FILE_lic)==0)
{
fgets(mystring,200,FILE_lic);
if((strstr(mystring,"INCREMENT"))||(strstr(mystring,"FEATURE")))
{
sscanf(mystring,"%s%s%s%s%s%d",check,uw1,vendor,uw2,date,&lic_num);
fprintf (FILE_list,"%s \t %s \t %d \n",vendor,date,lic_num);
}
}
}
}
}
}
Thanks in advance