hi, i posted yesterday asking about reading words from a file into an array. Someone (thank you whoever you are!) suggested the following code:
Code:
#include <stdio.h>
#include <ctype.h>
int main (void)
{
static const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file != NULL )
{
int ch, word = 0;
while ( (ch = fgetc(file)) != EOF )
{
if ( isspace(ch) || ispunct(ch) )
{
if ( word )
{
word = 0;
putchar('\n');
}
}
else
{
word = 1;
putchar(ch);
}
}
fclose(file);
}
return 0;
}
This sends the words to standard output but i want to store each word in an array in a linked list, how would i do this. Also, would it be better to use fscanf - if so what would the code look like?
thanks a lot