0

As you can see here valgrind is angry about some lines but I have no idea why, I've seem other people with similar problem here but different than mine.

Also, it seems my program can't handle the basic words test, except when I do it myself creating a dictionary with the words and a text file both containing "the quick brown fox jumps over the lazy dog" I pass the test, so that's weird.

There's some weird problem too when I run ./speller texts/ANYOFTHETEXTS sometimes I get the right ammount of misspeled words and sometimes I get more misspeled words than it actualy should be.

Here's my code:

[removed code per academic honesty guidelines]

Any help/tips will be much appreciated.

1
char loword[word_size+1];

for (int i=0, len = strlen(word); i<len; i++){
    if(word[i] != '\n'){
        loword[i] = tolower(word[i]);
    }else{
        loword[i] = word[i];
        loword[i+1] = '\0';
    }
}

You aren't actually null terminating your loword array. So this will cause undefined behavior (where sometimes your code works and other times it may not).

Move that assignment outside the loop.

(Also note that word[i] will never be '\n' since that will have been stripped by speller.c before calling check.)

1
  • Thank you a lot!!! – Freonzx Feb 27 '18 at 0:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .