18 Commits
Author SHA1 Message Date
wiesendsi102436 69f9945fe0 remove fclose() because it's already called in main.c 2025-11-02 20:28:35 +01:00
wiesendsi102436 0aa5c5e9e3 update gitignore 2025-11-02 20:25:54 +01:00
wiesendsi102436 ed4a9c7520 sync linux folder 2025-11-02 20:24:02 +01:00
uhlmannja101588 26bc089865 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/wiesendsi102436/info2Praktikum-Wortsalat 2025-11-02 14:38:05 +01:00
uhlmannja101588 90827c9ad6 input.c besteht alle Tests 2025-11-02 13:21:15 +01:00
Fabrice 147fc502eb kleine Änderungen 2025-10-31 09:29:12 +01:00
wiesendsi102436 27eafd14cc Merge pull request 'simon' (#3) from simon into main
Reviewed-on: wiesendsi102436/info2Praktikum-Wortsalat#3
2025-10-31 08:05:56 +00:00
wiesendsi102436 4041e9ee9b clean up 2025-10-31 09:05:06 +01:00
wiesendsi102436 11871e8c65 return error if some words couldn't be placed 2025-10-31 08:55:47 +01:00
wiesendsi102436 6244fad3d4 update gitignore 2025-10-31 08:34:32 +01:00
wiesendsi102436 67a8247535 merge upstream 2025-10-31 07:30:19 +00:00
wiesendsi102436 5fbc71cf03 Merge pull request 'simon' (#2) from simon into main
Reviewed-on: wiesendsi102436/info2Praktikum-Wortsalat#2
2025-10-31 07:20:04 +00:00
wiesendsi102436 c97f4bd97d sync linux folder 2025-10-31 08:19:03 +01:00
wiesendsi102436 1098b0f8c0 init random number generator 2025-10-31 08:18:19 +01:00
Fabrice dc9b59395b game.c bearbeitet,noch nicht fertig 2025-10-31 00:25:02 +01:00
wiesendsi102436 d7c0c30de9 Merge pull request 'add gitignore file' (#1) from gitignore into main
Reviewed-on: wiesendsi102436/info2Praktikum-Wortsalat#1
2025-10-24 07:25:50 +00:00
wiesendsi102436 dcb1e44c98 add more gcc output files 2025-10-24 09:17:31 +02:00
wiesendsi102436 970ce3049a add .gitignore and ignore wordsalad_initial bin file 2025-10-24 08:13:24 +02:00
7 changed files with 175 additions and 8 deletions
+13
View File
@@ -0,0 +1,13 @@
wordsalad_initial
game.o
input.o
runTests
main.o
graphicalGame.o
wordsalad
wordsalad_initial.exe
runTests.exe
testwords_delims.txt
testwords_empty.txt
testwords_simple.txt
.vscode
+37
View File
@@ -13,11 +13,48 @@
// 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(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{ {
// set seed for random number generator
srand(time(NULL));
int r, c;
//Gesamtes Feld auf 0 setzen
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
salad [r][c] = EMPTY_CHAR;
}
}
//Wörter zufällig horizontal oder vertikal platzieren
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
enum Richtung dir;
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
//Prüfen, ob das Wort von der Länge her ins Feld passt
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad [r][c] = 'A' + (rand()% 26);
}
}
}
return 0;
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
int r, c;
//Ausgabe des gesamten Feldes
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
printf("%c ", salad[r][c]);
}
printf("\n");
}
} }
+33
View File
@@ -1,4 +1,5 @@
#include "input.h" #include "input.h"
#include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@@ -6,7 +7,39 @@
// 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.
// 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 count = 0;
if (file == NULL)
{
return 1;
}
while (fgets(buffer, sizeof(buffer), file) != NULL)
{
// Zerlege Zeile in einzelne Wörter anhand der Trennzeichen
char *token = strtok(buffer, " ,;\n");
while (token != NULL && count < maxWordCount)
{
// In Großbuchstaben umwandeln
for (int i = 0; token[i] != '\0'; i++)
{
token[i] = toupper((unsigned char)token[i]);
}
// Token in das words-Array kopieren
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren
count++;
// Nächsten Token holen
token = strtok(NULL, " ,;\n");
}
}
return count;
} }
+10 -3
View File
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
int exitCode = EXIT_SUCCESS; int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided // Check if the correct number of arguments is provided
if(argc != 2) if (argc != 2)
{ {
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]); fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
FILE *file = fopen(argv[1], "r"); FILE *file = fopen(argv[1], "r");
if(file != NULL) if (file != NULL)
{ {
unsigned int placedWords = 0; unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
@@ -36,11 +36,18 @@ 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:
// 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)
{
fprintf(stderr, "some words couldn't be placed\n");
exitCode = EXIT_FAILURE;
}
// TODO:
// Start the game if successful
} }
else else
{ {
+37
View File
@@ -13,11 +13,48 @@
// 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(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{ {
// set seed for random number generator
srand(time(NULL));
int r, c, placedWords=0;
//Gesamtes Feld auf 0 setzen, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
salad [r][c] = EMPTY_CHAR;
}
}
//Wörter zufällig horizontal oder vertikal platzieren
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
enum Richtung dir;
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
//Prüfen, ob das Wort von der Länge her ins Feld passt
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad [r][c] = 'A' + (rand()% 26);
}
}
}
//return "Anzahl platzierter Wörter", wird in Main dann mit soll verglichen
return placedWords;
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
int r, c;
//Ausgabe des gesamten Feldes
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
printf("%c ", salad[r][c]);
}
printf("\n");
}
} }
+33
View File
@@ -1,4 +1,5 @@
#include "input.h" #include "input.h"
#include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@@ -6,7 +7,39 @@
// 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.
// 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 count = 0;
if (file == NULL)
{
return 1;
}
while (fgets(buffer, sizeof(buffer), file) != NULL)
{
// Zerlege Zeile in einzelne Wörter anhand der Trennzeichen
char *token = strtok(buffer, " ,;\n");
while (token != NULL && count < maxWordCount)
{
// In Großbuchstaben umwandeln
for (int i = 0; token[i] != '\0'; i++)
{
token[i] = toupper((unsigned char)token[i]);
}
// Token in das words-Array kopieren
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren
count++;
// Nächsten Token holen
token = strtok(NULL, " ,;\n");
}
}
return count;
} }
+10 -3
View File
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
int exitCode = EXIT_SUCCESS; int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided // Check if the correct number of arguments is provided
if(argc != 2) if (argc != 2)
{ {
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]); fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
FILE *file = fopen(argv[1], "r"); FILE *file = fopen(argv[1], "r");
if(file != NULL) if (file != NULL)
{ {
unsigned int placedWords = 0; unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
@@ -36,11 +36,18 @@ 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:
// 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)
{
fprintf(stderr, "some words couldn't be placed\n");
exitCode = EXIT_FAILURE;
}
// TODO:
// Start the game if successful
} }
else else
{ {