You're still making the same error quzah pointed out above.
Originally Posted by
quzah
A char can NEVER contain the EOF marker.
Also, how does GetWord know that it won't overrun the string buffer?
Originally Posted by
pianorain
Something you may want to add is a buffer length to your function; you don't want to be running off the end of your buffer.
What if the file you open is an empty file?
Code:
int GetWord(FILE *inp, char *string)
{
int i=0;
char ch;
ch = fgetc ( inp ); //might be EOF
do
{
string[i] = ch; //whoops, EOF in the string
//snip
And how are you null-terminating your string?
See what you can make of this pseudo-code:
Code:
//returns true if string contains a word
//returns false if hit EOF and string does not contain a word
int GetWord(FILE *inp, char *string, int len)
{
//start index at 0
//while we have room in the string
//get the character from the file
//if at the end of file, break
//if found a space, break
//put the character into the string
//increment the index into the string
//end while
//null-terminate the string
//return a meaningful value
}