generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56b3b9efa1 | |||
| b4cc13d96a | |||
| 765879d085 | |||
| 3d0b1d6729 |
@ -121,4 +121,4 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -8,28 +8,132 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
||||
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
||||
int i;
|
||||
// MAX_WORD_LEN 100
|
||||
// MAX_LINE_LEN 1024
|
||||
// *file ist Datei
|
||||
// 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)
|
||||
{
|
||||
char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
|
||||
char *parts = strtok(puffer, ",;\n\t/. ");
|
||||
|
||||
while(word_parts != NULL && counter < maxWordCount)
|
||||
while(parts != NULL && counter < maxWordCount)
|
||||
{
|
||||
// Kopiere das Wort in words-Array
|
||||
strncpy(words[counter], word_parts, MAX_WORD_LEN - 1);
|
||||
words[counter][MAX_WORD_LEN - 1] = '\0';
|
||||
|
||||
// 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
|
||||
//strncpy(words[counter][MAX_WORD_LEN], puffer, MAX_LINE_LEN-1);
|
||||
//words[counter][MAX_WORD_LEN-1] = "\0";
|
||||
//Großbuchstaben
|
||||
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/. ");
|
||||
|
||||
}
|
||||
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,19 +36,19 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// TODO: (if Schleife implementieren, die das prüft)
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
if (placedWords == wordCount){
|
||||
startGame(wordSalad,SALAD_SIZE,words, wordCount,750);
|
||||
showWordSalad(wordSalad, placedWords);
|
||||
}
|
||||
else
|
||||
{
|
||||
else{
|
||||
printf("Error. The words couldn't be placed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -59,4 +59,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@ -33,9 +33,9 @@ graphicalGame.o: graphicalGame.c
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
TEST_BIN = runTests2
|
||||
TEST_BIN = runTests
|
||||
|
||||
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
|
||||
|
||||
# --------------------------
|
||||
@ -43,7 +43,6 @@ test: input.o game.o unit_tests.c
|
||||
# --------------------------
|
||||
clean:
|
||||
del /f *.o *.exe
|
||||
#hier eigene wordsalad kopieren, library rauslassen
|
||||
|
||||
wordsalad_myversion: main.o input.o game.o graphicalGame.o
|
||||
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a
|
||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a $(LDFLAGS)
|
||||
|
||||
Binary file not shown.
70
Start_Windows/test.c
Normal file
70
Start_Windows/test.c
Normal file
@ -0,0 +1,70 @@
|
||||
#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 +0,0 @@
|
||||
Hund,Katze; Maus
|
||||
@ -1,3 +0,0 @@
|
||||
Apfel
|
||||
Banane
|
||||
Kiwi
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user