31 lines
859 B
C
31 lines
859 B
C
#include "input.h"
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
// Liest Wörter aus Datei und speichert sie sicher im Array
|
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
{
|
|
char buffer[MAX_WORD_LEN];
|
|
unsigned int count_word = 0;
|
|
|
|
while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
|
|
{
|
|
// Zeilenumbruch manuell entfernen
|
|
for (int i = 0; i < MAX_WORD_LEN; i++)
|
|
{
|
|
if (buffer[i] == '\n' || buffer[i] == '\r')
|
|
{
|
|
buffer[i] = '\0';
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Sicheres Kopieren in das Zielarray
|
|
strncpy(words[count_word], buffer, MAX_WORD_LEN - 1);
|
|
words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung sicherstellen
|
|
|
|
count_word++;
|
|
}
|
|
|
|
return count_word;
|
|
} |