gus_m
asked on
Segmentation fault after running in linux
Hi, i'm making this program in c.. when i run it under DOS.. works perfecly, and when i run it in linux i get segmentation fault.. i can't understand why.. PLEASE help.
void setParam(indice *ind,par p)
{
/*here i get segmentation fault after this function is called from
tag_beg_end_mode function */
ind->params=p;
}
/* This function receive setParam function as a parameter */
int tag_beg_end_mode(FILE *aFile,int tag,indice *elem,
void (*f)(indice *elemento,par p))
{ etiqueta startMark,endMark;
if (validate_open_close(aFile ,&startMar k,&endMark ,tag))
{ par dato;
setPair(&dato,snd(getBegEn d(startMar k)),fst(ge tBegEnd(en dMark)));
( (*f)(elem,dato) );
return 1;}
return 0;
}
int complete_function(FILE *aFile,int tag,indice *aux)
{
return ((tag_beg_end_mode(aFile,t ag++,aux,s etParam));
}
No matter what i do in setParam function, whenever i use their params i get segmentation fault.
Thanx.. Gus
void setParam(indice *ind,par p)
{
/*here i get segmentation fault after this function is called from
tag_beg_end_mode function */
ind->params=p;
}
/* This function receive setParam function as a parameter */
int tag_beg_end_mode(FILE *aFile,int tag,indice *elem,
void (*f)(indice *elemento,par p))
{ etiqueta startMark,endMark;
if (validate_open_close(aFile
{ par dato;
setPair(&dato,snd(getBegEn
( (*f)(elem,dato) );
return 1;}
return 0;
}
int complete_function(FILE *aFile,int tag,indice *aux)
{
return ((tag_beg_end_mode(aFile,t
}
No matter what i do in setParam function, whenever i use their params i get segmentation fault.
Thanx.. Gus
My guess is that somehow the 'ind' pointer in setParam() is invalid. The first thing I would do is ensure that the value of 'ind' is the same inside setParam() as 'aux' is inside complete_function(). If it is, then I'd check to see the call to complete_function() to verify that 'aux' is being set correctly in the call. If the pointer variables have different values, then you'll need to narrow down (likely inside tag_beg_end_mode()) where the pointer variable is getting overwritten.
ASKER
the complete_function function is called from another
int process_file(char *aFileName,vecIndice *vIndices)
{
FILE *file;
if ((file=fopen(aFileName,"rt "))!=NULL)
{ indice aux;
int tag=0,i=0;
createIndex(vIndices);
while (!reach_end(file)&&complet e_function (file,tag, &aux))
insertInIndex(vIndices,&au x);
if (reach_end(file))
{ fclose(file);
return 1;
}
fclose(file);
}else printf("File Error");
return 0;
}
int process_file(char *aFileName,vecIndice *vIndices)
{
FILE *file;
if ((file=fopen(aFileName,"rt
{ indice aux;
int tag=0,i=0;
createIndex(vIndices);
while (!reach_end(file)&&complet
insertInIndex(vIndices,&au
if (reach_end(file))
{ fclose(file);
return 1;
}
fclose(file);
}else printf("File Error");
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It has nothing to do with the problem you describe, but your 'tag' variables don't seem to do anything. In process_file(), tag is always 0. In complete_function, you increment tag, but since you return right away, the ++ is useless.
ASKER
I give you the points cause you were the only one who realized that it was a parser, it is very similar.
I've already done what you said, and it works perfecly in DOS but somehow it doesn't work in linux..
Thanx anyway.
Gustavo
PD: if you still want to help me, here is my e-mail. gustavo_mazzei@speedy.com. ar
I've already done what you said, and it works perfecly in DOS but somehow it doesn't work in linux..
Thanx anyway.
Gustavo
PD: if you still want to help me, here is my e-mail. gustavo_mazzei@speedy.com.
Try debuging it with GDB or simply print the pointer of ind parameter.
Also, watch for path names in Linux (I see a FILE structure there, is the file succesfully opened?).