Originally Posted by
matsp
That indicates that there is a '\r' [carriage return] at the end of the line - can you post:
1. Code that opens the "valid word list".
2. Code that reads the word.
3. Code that removes newline.
I suspect you are reading the file in binary mode, but it could be other things.
Using the "print in hex" variation will show you that it's got a 0D character at the end of the string, I suspect.
--
Mats
While i do the printing in hex.. here are the codes:
Code that opens the 'valid word list':
Code:
FILE *dict;
dict = fopen(filename, "r");
Code that reads the word:
Code:
for (i=0; fgets(words[i], sizeof(words[i]), dict) != NULL; i++);
Code that removes newline:
Code:
/* remove the newline characters from each word */
for (i=0; i<sizeof(words)/sizeof(words[0]); i++) {
char *p = strchr(words[i],'\n');
if(p) {
*p = '\0';
}
}
EDIT: I did the printing in hex for the words[], and 0D was at the end of the last element in the array -
6C696E6531D <-- word[0]
6C696E6532D <-- word[1]
6C696E6533D <-- word[2]
...
6C696E653130D <-- word[9]
(in my 'dictionary' of 10 words)