while ((c = fgetc(fp)) != EOF) {
if( isalpha(c) && i < 30) {
word[i++] = tolower(c);
} else {
add_word(word, list, i);
word[0] = '\0';
i = 0;
}
}
I’ve debugged it a little and it seems it crashes where it says word[i++] = tolower©; word is a chararray with 30 elements (char word[30]) so I understand if I get seg-fault when trying to access say element 31, but I know im not doint it here since I’ve added i < 30 in the while statement. Now this code is supposed to read words from a while, one character at a time. And when it encounters word larger than 30 chars, it crashes and give me the segfault error. I use gcc 4.1.1 at home… But this EXACT same code works with no problems whatsoever at school, where they use gcc 3.3.5.
When running gdb, it says it recieved a SIGSEV signal from getc(). I’m not using getc, so i guess gdb is referring to fgetc?
Does this problem have anything to do with gcc or is it just my computer beeing a *****???
I’ve already mailed my teacher but was hoping you guys could help me out too…