Fscanf segmentation fault issue (I think)
I have my little program that has to read a number of words from different files, insert them into some skip-lists and do some other stuff afterwards.
I was given 3 tests to check the program's functionality.
For the first two tests, it works splendidly. However, the last one has a rough estimation of a few hundred thousand words in it and the fscanf() function that I use to read the files with makes the program crash after reading about 50.000 words.
Here's where the problem should be located (If the problem IS with the fscanf() function).
Note: English isn't my native language, so some of the variable names may seem strange to you :)
Code:
while(fscanf(definitii,"%s",aux) && !feof(definitii))
{
if(aux[strlen(aux)-1]==':')
{
if(n>0)
nr_elem[n-1]=nr_cuv;
L=realloc(L,(n+1)*sizeof(List*));
L[n]=NULL;
tabel_def=(char**)realloc(tabel_def,(n+1)*sizeof(char*));
tabel_def[n]=(char*)malloc(strlen(aux));
for(j=0;j<strlen(aux);j++)
aux[j]=tolower(aux[j]);
aux[strlen(aux)-1]='\0';
strncpy(tabel_def[n],aux,strlen(aux)+1);
nr_cuv=0;
n++;
}
else
{
if(strlen(aux)>=3 && isValidString(aux))
{
nr_cuv++;
for(j=0;j<strlen(aux);j++)
aux[j]=tolower(aux[j]);
insert(&(L[n-1]),strtok(aux,"(),.;- "));
}
}
free(aux);
aux=malloc(100);
}
Any help or constructive criticism is greatly appreciated. :)