generated from freudenreichan/info2Praktikum-Wortsalat
Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/eckardtni105737/Info2PrWortsalat
This commit is contained in:
commit
221e0e7168
4 files changed
+63
-7
No files matched your search
@@ -37,6 +37,9 @@
|
|||||||
*.hex
|
*.hex
|
||||||
Startcode/wordsalad_initial
|
Startcode/wordsalad_initial
|
||||||
Startcode/wordsalad
|
Startcode/wordsalad
|
||||||
|
Startcode/wordsalad_mymain
|
||||||
|
Startcode/wordsalad_myinput
|
||||||
|
Startcode/runTests
|
||||||
test
|
test
|
||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
|
|||||||
+40
-2
@@ -2,11 +2,49 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
// TODO:
|
/*
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
Read a single word from file and store it in buffer.
|
||||||
|
Returns the length of the word, or 0 if no more words are available (EOF).
|
||||||
|
*/
|
||||||
|
static int readSingleWord(FILE *file, char buffer[MAX_WORD_LEN])
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
//clear leading seperators
|
||||||
|
while((c = fgetc(file)) != EOF && (c == ',' || c == ';' || c == ' ' || c == '\n')) {}
|
||||||
|
|
||||||
|
//check for empty file
|
||||||
|
if(c == EOF)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
//read word
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(len < MAX_WORD_LEN - 1) // -1 to leave space for '\0'
|
||||||
|
{
|
||||||
|
buffer[len] = toupper((unsigned char)c);
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
c = fgetc(file);
|
||||||
|
}
|
||||||
|
while(c != EOF && !(c == ',' || c == ';' || c == ' ' || c == '\n'));
|
||||||
|
|
||||||
|
//append string end-delimiter
|
||||||
|
buffer[len] = '\0'; // '\0' marks the end of a string, we need to apend it for strcpy
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
// 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], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
char buffer[MAX_WORD_LEN];
|
||||||
|
unsigned int wordCount = 0;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
while(wordCount < maxWordCount && (len = readSingleWord(file, buffer)) > 0)
|
||||||
|
strcpy(words[wordCount++], buffer);
|
||||||
|
|
||||||
|
return wordCount;
|
||||||
}
|
}
|
||||||
+9
-4
@@ -36,10 +36,15 @@ int main(int argc, char *argv[])
|
|||||||
// Create the word salad by placing words into grid
|
// Create the word salad by placing words into grid
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||||
|
|
||||||
// TODO:
|
if (wordCount == placedWords)
|
||||||
// Check if all words were successfully placed
|
{
|
||||||
// Start the game if successful
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 1000);
|
||||||
// error message if some words couldn't be placed
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Not all words could be placed in the grid.\nOnly %d of %d could be placed", placedWords, wordCount);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
+11
-1
@@ -22,6 +22,16 @@ codefolder = .
|
|||||||
wordsalad_initial:
|
wordsalad_initial:
|
||||||
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Zwischenstände:
|
||||||
|
# --------------------------
|
||||||
|
# Only main
|
||||||
|
wordsalad_mymain: main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_mymain main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
# Main + Input
|
||||||
|
wordsalad_myinput: main.o input.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_myinput main.o input.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@@ -55,5 +65,5 @@ clean:
|
|||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
del /f *.o *.exe
|
del /f *.o *.exe
|
||||||
else
|
else
|
||||||
rm -f *.o wordsalad $(TEST_BIN)
|
rm -f *.o wordsalad wordsalad_mymain wordsalad_myinput $(TEST_BIN)
|
||||||
endif
|
endif
|
||||||
Reference in new issue
Block a user