forked from freudenreichan/info2Praktikum-Wortsalat
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5837d86ad | ||
|
|
e2df312438 | ||
|
|
f8deef43e1 | ||
|
|
a1a0b615a7 |
No files matched your search
+1
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user