generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e551a025be | ||
|
|
b427e8e547 | ||
|
|
5f567fa968 | ||
|
|
36bfbcb156 | ||
|
|
a78c1e2ea2 | ||
|
|
c18b6a4529 | ||
|
|
013eba7b3d | ||
|
|
cd3dd0a4d6 | ||
|
|
b9138e2097 | ||
|
|
28a2aa1ea1 | ||
|
|
cddbfb3029 | ||
|
|
5c1aea7a88 | ||
|
|
f47f3aef7c | ||
|
|
b34074233d | ||
|
|
bbad6afd45 | ||
|
|
9e172b664f | ||
|
|
c26a55f965 | ||
|
|
16b0b9a450 | ||
|
|
85a79e9235 | ||
|
|
506c091bf6 | ||
|
|
4fea2c9f7b | ||
|
|
817f35a154 | ||
|
|
19787739a7 | ||
|
|
3657ee5ff7 | ||
|
|
099243b5e2 | ||
|
|
1db2042e38 |
Binary file not shown.
@ -8,132 +8,28 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
// MAX_WORD_LEN 100
|
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
||||||
// MAX_LINE_LEN 1024
|
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
||||||
// *file ist Datei
|
int i;
|
||||||
// words ist Array
|
|
||||||
// MAX_WORD_LEN ist maximale Wortlänge
|
|
||||||
// maxWordCount ist maximale Anzahl an Wörtern
|
|
||||||
char puffer[MAX_LINE_LEN];
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
||||||
{
|
{
|
||||||
char *parts = strtok(puffer, ",;\n\t/. ");
|
char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
|
||||||
|
|
||||||
while(parts != NULL && counter < maxWordCount)
|
while(word_parts != NULL && counter < maxWordCount)
|
||||||
{
|
{
|
||||||
//strncpy(words[counter][MAX_WORD_LEN], puffer, MAX_LINE_LEN-1);
|
// Kopiere das Wort in words-Array
|
||||||
//words[counter][MAX_WORD_LEN-1] = "\0";
|
strncpy(words[counter], word_parts, MAX_WORD_LEN - 1);
|
||||||
//Großbuchstaben
|
words[counter][MAX_WORD_LEN - 1] = '\0';
|
||||||
for(int i = 0; i < MAX_WORD_LEN -1 && parts[i] != '\0'; i++)
|
|
||||||
{
|
|
||||||
words[counter][i] = toupper(parts[i]);
|
|
||||||
words[counter][i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
counter++; // Wort eingelesen -> Wortzähler erhöhen
|
|
||||||
parts = strtok(NULL, ",;\n\t/. ");
|
|
||||||
|
|
||||||
|
// Alles in Großbuchstaben umwandeln
|
||||||
|
for(i = 0; words[counter][i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
words[counter][i] = toupper(words[counter][i]);
|
||||||
|
}
|
||||||
|
counter++; // Wort eingelesen, Wortzähler erhöhen
|
||||||
|
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* #include "input.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
|
||||||
#define MAX_WORD_LEN 100
|
|
||||||
// TODO:
|
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
|
||||||
|
|
||||||
// Read words from file and store in 'words' array
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
||||||
{
|
|
||||||
char line [MAX_WORD_LEN];
|
|
||||||
printf("H");
|
|
||||||
|
|
||||||
int j = 0;
|
|
||||||
int count = 0;
|
|
||||||
char single_word[MAX_WORD_LEN];
|
|
||||||
|
|
||||||
while(fgets(line, MAX_WORD_LEN, file) != NULL ){
|
|
||||||
|
|
||||||
printf("A");
|
|
||||||
for(int i = 0; line[i] != '\0'; i++){
|
|
||||||
printf("L");
|
|
||||||
|
|
||||||
|
|
||||||
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
|
|
||||||
if (isalpha(line[i]) != 0){
|
|
||||||
single_word[j++] = toupper(line[i]);
|
|
||||||
}
|
|
||||||
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
|
|
||||||
else{
|
|
||||||
single_word[j] = '\0';
|
|
||||||
strncpy(words[count], single_word, MAX_WORD_LEN);
|
|
||||||
count++;
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(int n = 0; n < count ; n++)
|
|
||||||
{
|
|
||||||
printf("%s \n", words[n]);
|
|
||||||
printf("O");
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
int wordCount = 0;
|
|
||||||
FILE *file = fopen("word.txt", "r");
|
|
||||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
|
||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
|
||||||
fclose(file);
|
|
||||||
return wordCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 1. Versuch
|
|
||||||
while(fgets(line, maxWordCount, file) != NULL ){
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int count = 0;
|
|
||||||
char line [MAX_WORD_LEN];
|
|
||||||
|
|
||||||
|
|
||||||
while(line[i] != '\0' && line[i+1] != '\0'){
|
|
||||||
|
|
||||||
char single_word[MAX_WORD_LEN];
|
|
||||||
|
|
||||||
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
|
|
||||||
if (isalpha(line[i]) != 0){
|
|
||||||
single_word[i++] = toupper(line[i]);
|
|
||||||
|
|
||||||
}
|
|
||||||
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
|
|
||||||
else{
|
|
||||||
single_word[i++] = '\0';
|
|
||||||
strncpy(single_word, words, i)
|
|
||||||
words[i][0] = '\0';
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Binary file not shown.
@ -36,15 +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 Schleife implementieren, die das prüft)
|
// TODO:
|
||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
|
|
||||||
if (placedWords == wordCount){
|
if (placedWords == wordCount){
|
||||||
showWordSalad(wordSalad, placedWords);
|
startGame(wordSalad,SALAD_SIZE,words, wordCount,750);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
printf("Error. The words couldn't be placed.\n");
|
printf("Error. The words couldn't be placed.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -60,5 +60,3 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
@ -33,7 +33,7 @@ graphicalGame.o: graphicalGame.c
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
TEST_BIN = runTests
|
TEST_BIN = runTests2
|
||||||
|
|
||||||
test: input.o game.o unit_tests.c
|
test: input.o game.o unit_tests.c
|
||||||
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||||
@ -43,6 +43,7 @@ test: input.o game.o unit_tests.c
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
del /f *.o *.exe
|
del /f *.o *.exe
|
||||||
|
#hier eigene wordsalad kopieren, library rauslassen
|
||||||
|
|
||||||
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a
|
wordsalad_myversion: main.o input.o game.o graphicalGame.o
|
||||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a $(LDFLAGS)
|
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
BIN
Start_Windows/runTests2.exe
Normal file
BIN
Start_Windows/runTests2.exe
Normal file
Binary file not shown.
@ -1,70 +0,0 @@
|
|||||||
#include "input.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
|
|
||||||
// launch
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
||||||
{
|
|
||||||
char line [MAX_WORD_LEN];
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
|
||||||
int count = 0;
|
|
||||||
file = fopen("words.txt", "r");
|
|
||||||
char single_word[MAX_WORD_LEN];
|
|
||||||
|
|
||||||
while(fgets(line, maxWordCount, file) != NULL ){
|
|
||||||
|
|
||||||
|
|
||||||
while(line[i] != '\0' && line[i+1] != '\0'){
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
|
|
||||||
if (isalpha(line[i]) != 0){
|
|
||||||
single_word[j++] = toupper(line[i]);
|
|
||||||
|
|
||||||
}
|
|
||||||
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
|
|
||||||
else{
|
|
||||||
single_word[j++] = '\0';
|
|
||||||
strncpy(words[count], single_word, i);
|
|
||||||
i = 0;
|
|
||||||
count++;
|
|
||||||
int j = 0;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(int n = 0; n < count ; n++)
|
|
||||||
{
|
|
||||||
printf("%s \n", words[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
|
||||||
FILE*file;
|
|
||||||
unsigned int wordCount = 0;
|
|
||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
|
||||||
|
|
||||||
}
|
|
||||||
1
Start_Windows/testwords_delims.txt
Normal file
1
Start_Windows/testwords_delims.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hund,Katze; Maus
|
||||||
0
Start_Windows/testwords_empty.txt
Normal file
0
Start_Windows/testwords_empty.txt
Normal file
3
Start_Windows/testwords_simple.txt
Normal file
3
Start_Windows/testwords_simple.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Apfel
|
||||||
|
Banane
|
||||||
|
Kiwi
|
||||||
Binary file not shown.
BIN
Start_Windows/windows/unity.o
Normal file
BIN
Start_Windows/windows/unity.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user