29 lines
659 B
C
29 lines
659 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)
|
|
{
|
|
int wordLength = MAX_WORD_LEN;
|
|
|
|
//open file in read mode
|
|
file = fopen("words.txt", "r");
|
|
|
|
if(file == NULL)
|
|
{
|
|
printf("\nNot able to opne file.\n");
|
|
}
|
|
else
|
|
{
|
|
int n = 0;
|
|
|
|
while (n < MAX_WORDS && fscanf(file, "%49s", words[n]) == 1)
|
|
n++;
|
|
|
|
fclose(file);
|
|
}
|
|
} |