> the fscanf function gives a value of 30 to "number_of_words"
You mean this?
> fscanf(text,"%i",*number_of_words);
No, it doesn't.
The one I posted in #6 does however
fscanf(text,"%i",number_of_words);
> the fscanf function gives a value of 30 to "number_of_words"
You mean this?
> fscanf(text,"%i",*number_of_words);
No, it doesn't.
The one I posted in #6 does however
fscanf(text,"%i",number_of_words);
okay then can you recomend a code that would do what ive been tryna do
> the text file is simply a list of 30 ,5 letter words with number 30 at the top.
Say for example
30\n
hello\n
world\n
So here are your first couple of fscanf calls.
The first call with %i will consume 30Code:fscanf(text,"%i",number_of_words);
for (i=0;i<*number_of_words;i++)
{
for(j = 0; j <6 ; j++)
{
fscanf(text,"%c",words[i][j]);
The first 6 calls with %c will consume \nhello
The next 6 calls with %c will consume \nworld
On the whole, it might be better if you just did this, which will skip over all the white-space in the file.
Code:fscanf(text,"%i",number_of_words);
for (i=0;i<*number_of_words;i++)
fscanf(text,"%s",words[i]);
Now recall post #9
Quote:
But given that you're using %c to read the file, you need to understand that file format is critical. If you're out by even 1 character, then the program just won't work as expected.