# Help with C-code

**URL:** https://forum.kirupa.com/t/help-with-c-code/219731
**Category:** programming
**Created:** [March 19, 2007, 8:17pm UTC](https://forum.kirupa.com/t/help-with-c-code/219731 "2007-03-19T20:17:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Danii](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Danii](https://forum.kirupa.com/u/Danii)
#### Post date: [March 19, 2007, 8:17pm UTC](https://forum.kirupa.com/t/help-with-c-code/219731/1 "2007-03-19T20:17:22Z")

</div>

```auto

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…
