![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
Dude22
Hi, here is what I have so far, am I on the right track??? any hits/tips???
Code:
{
int number_of_words = 0;
FILE* inptr = fopen(dictionary, "r"); //use "dictionary", maybe "dictionary.txt" - you need the double quotes around the file name
if (inptr == NULL)
{
printf("Sorry, me noes able to open the file!!!\n");
return false;
}
else //you don't need the else at all.
{
// while(!feof(inptr)) don't use feof(). It doesn't work as you expect.
while((fgets(s, sizeof(s), inptr)) != NULL)
{
//fscanf(inptr, s);
number_of_words ++;
}
char words[number of words][29];
int times_written = 0;
/*What would be very nice is to put the word counter, into a function, then call the function twice, with an int count parameter.
When count==1, you count the words. When count==0, you read the words from the file. */
// nope = use the fgets() above while(!feof(inptr))
{
// fscanf(inptr, s, words[times_written])
times_written ++;
//add code to remove the end of string char from s, here
}
}
return true;
}
One problem that I know about is "s" as a modifier to fscanf is not being recognized, am I implementing it incorrectly???
No, fscanf() needs "%s". note the double quotes around the format string. But don't use fscanf() anyway. Use
Code:
#define SIZE 29 //before main, just below your include file list.
while((fgets(s, SIZE, inptr)) != NULL)