31 lines
714 B
C
31 lines
714 B
C
#include "input.h"
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
// TODO:
|
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
|
|
|
// Read words from file and store in 'words' array
|
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
{
|
|
|
|
char *teiler = " ,;";
|
|
char *token;
|
|
unsigned int counter =0;
|
|
|
|
token = strtok(file, teiler);
|
|
counter += 1;
|
|
strncpy(words, token, MAX_WORD_LEN);
|
|
token = strtok(NULL, teiler);
|
|
counter += 1;
|
|
|
|
while(token != NULL)
|
|
{
|
|
stncat(words, token, MAX_WORD_LEN);
|
|
token = strtok(NULL, teiler);
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
return counter;
|
|
} |