new_word is malloc'd later in the program...
*edit*
also, adding the !=EOF bit, doesnt help, and its only missing coz i check elsewhere (cant remember why XD )
The reason I'm quite sure its getc, is that if i put a print statement immediately before, and immediately after
eg:
Code:
printf("before\r\n");
c = getc(data);
printf("after\r\n");
The first print statement will appear, then it will seg fault...
That said, I'll attach a bit more of my code =S
Code:
int main(int argc, char *argv[])
{
create_hash_table(hash_total); // Set empty hash table
hash_type(0);
int verbose=0;
FILE *data;
char *data_file="NULL";
FILE *search;
char *search_file="NULL";
char tmp_arg;
.....
if(strcmp(data_file,"NULL")==0)
{
printf("No input file specified...\r\n");
return 0;
}
if((data = fopen(data_file,"r")) == NULL)
{
printf("Textfile failed to load...\r\n");
return;
}
prepro_words(data);
......
void prepro_words(FILE *data)
{
char c; // current character
char currword[TMP_WORD_LEN]; // current word
char *new_word; // Pointer to words that will be added to the array
int i=0; // word index counter
int wc=1; // word length counter
while(c = getc(data))
{
if(i>=wc*TMP_WORD_LEN)
{
int owc = wc++; // old word length counter
char tmp_word[owc*TMP_WORD_LEN];
strncpy(tmp_word,currword,owc*TMP_WORD_LEN-1);
free(currword);
char currword[wc*TMP_WORD_LEN];
strncpy (currword,tmp_word,owc*TMP_WORD_LEN-1);
free(tmp_word);
}
if(isalpha(c))
currword[i++] = (char) tolower((int) c);
.... etc