29 lines
991 B
C
29 lines
991 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)
|
|
{
|
|
//Erstellt Pointer auf textdokument
|
|
FILE *textdokument = fopen("words.txt", "r");
|
|
if (file == NULL) {
|
|
printf("words,txt konnte nicht geoffnet werden");
|
|
}
|
|
// ToDo 2D char Array um wörter zu speichern kommt hier rein
|
|
char word[MAX_WORD_LEN];
|
|
unsigned int count = 0;
|
|
while (fscanf(textdokument, "%s", word) != EOF && count < maxWordCount) {
|
|
// Kopiere das gelesene Wort in das 2D-Array
|
|
strncpy(words[count], word, MAX_WORD_LEN - 1);
|
|
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist
|
|
count++;
|
|
}
|
|
fclose(textdokument);
|
|
return count;
|
|
|
|
|
|
} |