3 Commits
Author SHA1 Message Date
dunkellu103850 bc80769399 Mein aktuelles Programm. 2026-10-28 10:48:03 +01:00
dunkellu103850 9f0c315134 Mein fertiger Input. 2026-10-28 09:36:11 +01:00
dunkellu103850 7d518049a1 TEST 0123456789 2026-10-13 14:48:43 +02:00
4 changed files with 43 additions and 89 deletions

No files matched your search

File renamed without changes.
+1 -51
View File
@@ -11,57 +11,7 @@
* restliche Felder mit zufälligen Buchstaben füllen */ * restliche Felder mit zufälligen Buchstaben füllen */
// Creates the word salad by placing words randomly and filling empty spaces // Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad( int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
unsigned int searchFieldLen,
const char words[][MAX_WORD_LEN],
unsigned int wordCount)
{ {
unsigned int placedWords = 0;
// 1. Spielfeld leeren
for (unsigned int i = 0; i < searchFieldLen; i++) {
for (unsigned int j = 0; j < searchFieldLen; j++) {
salad[i][j] = EMPTY_CHAR;
} }
}
// 2. Alle Wörter durchlaufen
for (unsigned int i = 0; i < wordCount; i++) {
size_t wordLen = strlen(words[i]);
// Leere oder zu lange Wörter überspringen
if (wordLen == 0 || wordLen > searchFieldLen) {
continue;
}
// 3. Platzierungsversuche
for (int attempt = 0;
attempt < MAX_RAND_TRIES_PER_WORD;
attempt++) {
unsigned int row = rand() % searchFieldLen;
unsigned int col = rand() % searchFieldLen;
int direction = rand() % 2;
int canPlace = 1;
// 4. Horizontale Platzierung prüfen
if (direction == 0) {
if (col + wordLen > searchFieldLen) {
continue;
}
for (size_t j = 0; j < wordLen; j++) {
if (salad[row][col + j] != EMPTY_CHAR &&
salad[row][col + j] != words[i][j]) {
canPlace = 0;
break;
}
}
}
// 5. Vertikale Platzierung prüfen
+28 -34
View File
@@ -4,49 +4,43 @@
// TODO: // TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Test 123
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
unsigned int maxWordCount)
{ {
unsigned int wordCount = 0; int c = 0;
unsigned int charIndex = 0; int count = 0;
int c; int letterCount = 0;
while (count < maxWordCount)
if (file == NULL) { {
return 0; while ((c = fgetc(file)) != EOF) //Leerzeichen prüfen
{
if (isspace(c) || !isalpha(c)) {
if (letterCount > 0) {
break; //Wort fertig eingelesen
} }
while ((c = fgetc(file)) != EOF) { continue; // mehrere Leerzeichen oder Sonderzeichen überspringen
if (c == ',' || c == ';' || c == ' ' ||
c == '\n' || c == '\t' || c == '\r') {
if (charIndex > 0) {
words[wordCount][charIndex] = '\0';
wordCount++;
charIndex = 0;
if (wordCount >= maxWordCount) {
return (int)wordCount;
} }
}
}
else {
if (wordCount < maxWordCount &&
charIndex < MAX_WORD_LEN - 1) {
words[wordCount][charIndex] = (char)c; if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen
charIndex++; {
} words[count][letterCount] = (char)toupper(c);
letterCount++;
} }
} }
if (charIndex > 0 && wordCount < maxWordCount) { if (letterCount == 0) {
words[wordCount][charIndex] = '\0'; break; //kein weiteres Wort gefunden
wordCount++;
} }
return (int)wordCount; words[count][letterCount] = '\0';
letterCount = 0;
count++;
if (c == EOF) {
break;
}
}
return count;
} }
+14 -4
View File
@@ -1,5 +1,15 @@
Yeti,Nessie Werwolf; Vampir Yeti
Nessie
Werwolf
Vampir
Monster Monster
Hydra;Frankenstein Hydra
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist Frankenstein
Gespenst, Oger Dracula
KingKong
Gremlin
Kobold
Hexe
Poltergeist
Gespenst
Oger