26 lines
867 B
C
26 lines
867 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.
|
|
char* readSingleWord(FILE *file, char *destination, int maxLen)
|
|
{
|
|
char buffer[256]; // Zwischenspeicher zum einlesen
|
|
if (fgets(buffer, sizeof(buffer), file) != NULL)
|
|
{
|
|
buffer[strcspn(buffer, "\r\n")] = '\0'; // Entfernt Umbrüche
|
|
|
|
strncpy(destination, buffer, maxLen - 1);
|
|
destination[maxLen - 1] = '\0'; // Zwingendes Ende des C-Strings setzen, verhindert Pufferüberlauf
|
|
|
|
return destination; //Rückgabe bei Erfolg
|
|
}
|
|
return NULL; //Rückgabe nur bei Dateiende
|
|
}
|
|
|
|
// Read words from file and store in 'words' array
|
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
{
|
|
|
|
} |