32 lines
782 B
C
32 lines
782 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 puffer[MAX_WORD_LEN];
|
|
char *teiler = " ,;";
|
|
char *token;
|
|
unsigned int wordCount = 0;
|
|
|
|
fgets(puffer, MAX_LINE_LEN, file);
|
|
|
|
token = strtok(puffer, teiler);
|
|
|
|
while(token != NULL && wordCount < maxWordCount)
|
|
{
|
|
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
|
|
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
|
|
|
wordCount++;
|
|
|
|
token =strtok(NULL, teiler);
|
|
|
|
}
|
|
|
|
return wordCount;
|
|
} |