Author SHA1 Message Date
Angelos c5837d86ad Spielfeld wieder größer gemacht 2026-10-22 17:00:56 +02:00
Angelos e2df312438 gametest file entfernt 2026-10-22 16:16:52 +02:00
Mihaela Creciun f8deef43e1 Worteinlesen mit strncpy angepasst 2026-10-21 13:55:13 +02:00
Mihaela Creciun a1a0b615a7 Implementierung der Worteinlesefunktion 2026-10-20 22:18:24 +02:00
3 changed files with 44 additions and 34 deletions

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
#include "input.h"
#define MAX_SEARCH_FIELD_LEN 20
#define MAX_SEARCH_FIELD_LEN 100
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
-33
View File
@@ -1,33 +0,0 @@
#include <stdio.h>
#include "graphicalGame.h"
#include "game.h"
int main(void)
{
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
char words[][MAX_WORD_LEN] = {
"HALLO",
"WELT",
"AUTO",
"BIRNE",
"APFEL",
"BANANE",
"LANGESWORT",
"REITSPORT",
"APFELBAUM",
"DRACULA",
"LAPTOP",
"BILDSCHRIM",
"HAUS"
};
unsigned int wordCount = sizeof(words) / sizeof(words[0]);
int placedWords = createWordSalad(salad, MAX_SEARCH_FIELD_LEN, words, wordCount);
startGame(salad, MAX_SEARCH_FIELD_LEN, words, wordCount, 1000);
printf("Placed words: %d\n", placedWords);
return 0;
}
+43
View File
@@ -8,5 +8,48 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
unsigned int count = 0;
char currentWord[MAX_WORD_LEN];
size_t length = 0;
int tooLong = 0;
int ch;
while (count < maxWordCount && (ch = fgetc(file)) != EOF) {
if (ch == ',' || ch == ';' || isspace((unsigned char)ch)) {
if (length > 0 && !tooLong) {
currentWord[length] = '\0';
strncpy(words[count], currentWord, MAX_WORD_LEN);
count++;
}
length = 0;
tooLong = 0;
}
else if (!tooLong) {
if (length < MAX_WORD_LEN - 1) {
currentWord[length] = (char)toupper((unsigned char)ch);
length++;
}
else {
tooLong = 1;
length = 0;
}
}
}
if (count < maxWordCount && length > 0 && !tooLong) {
currentWord[length] = '\0';
strncpy(words[count], currentWord, MAX_WORD_LEN);
count++;
}
return (int)count;
}