Kommentare hinzugefügt
This commit is contained in:
parent
9b576835cb
commit
ae5e73e688
@ -15,14 +15,14 @@
|
|||||||
// 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) {
|
||||||
int addedWords = 0;
|
int addedWords = 0;
|
||||||
int attempts = 0;
|
int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen
|
||||||
int added = 0;
|
int added = 0; //0 Wort nicht hinzugefügt , 1 Wort hinzugefügt
|
||||||
int space = 1;
|
int space = 1; // 0 Wort zu lang, 1 Wort passt an diese Stelle
|
||||||
unsigned long long wordLength = 0;
|
unsigned long long wordLength = 0;
|
||||||
|
|
||||||
for (int i = 0; i < searchFieldLen; i++) {
|
for (int i = 0; i < searchFieldLen; i++) {
|
||||||
for (int j = 0; j < searchFieldLen; j++) {
|
for (int j = 0; j < searchFieldLen; j++) {
|
||||||
salad[i][j] = EMPTY_CHAR;
|
salad[i][j] = EMPTY_CHAR; //Füllen des gesamten Arrays mit Nullen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i=0; i < wordCount; i++) {
|
for (int i=0; i < wordCount; i++) {
|
||||||
@ -30,25 +30,27 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
wordLength = strlen(words[i]);
|
wordLength = strlen(words[i]);
|
||||||
|
|
||||||
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) {
|
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) {
|
||||||
int direction = rand() % 2;
|
int direction = rand() % 2;// 0 Horizontal, 1 Vertikal
|
||||||
if (direction == 0) {
|
if (direction == 0) {
|
||||||
int collumn = rand() % searchFieldLen;
|
int collumn = rand() % searchFieldLen;
|
||||||
int row = rand() % searchFieldLen;
|
int row = rand() % searchFieldLen;
|
||||||
for (int j = 0; j < wordLength; j++)
|
for (int j = 0; j < wordLength; j++)
|
||||||
{
|
{
|
||||||
if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;}
|
if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;}
|
||||||
|
//Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
|
||||||
}
|
}
|
||||||
if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
|
if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
|
||||||
|
//Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt
|
||||||
else {for (int j = 0; j < wordLength; j++)
|
else {for (int j = 0; j < wordLength; j++)
|
||||||
{
|
{
|
||||||
salad[row][collumn+j] = words[i][j];
|
salad[row][collumn+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
|
||||||
}
|
}
|
||||||
added=1;
|
added=1;
|
||||||
addedWords++;
|
addedWords++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (direction == 1) {
|
else if (direction == 1) {// Vertikal funktioniert analog zu horizontal
|
||||||
int collumn = rand() % searchFieldLen;
|
int collumn = rand() % searchFieldLen;
|
||||||
int row = rand() % searchFieldLen;
|
int row = rand() % searchFieldLen;
|
||||||
for (int j = 0; j < wordLength; j++)
|
for (int j = 0; j < wordLength; j++)
|
||||||
@ -75,7 +77,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
for (int j = 0; j < searchFieldLen; j++) {
|
for (int j = 0; j < searchFieldLen; j++) {
|
||||||
if (salad[i][j] == EMPTY_CHAR)
|
if (salad[i][j] == EMPTY_CHAR)
|
||||||
{
|
{
|
||||||
salad[i][j] = rand()%('Z'-'A'+1)+'A';
|
salad[i][j] = rand()%('Z'-'A'+1)+'A';//Alle Felder, die noch nicht befüllt sind, werden zufällig befüllt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -90,7 +93,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
|||||||
{
|
{
|
||||||
for(int j = 0; j < searchFieldLen; j++)
|
for(int j = 0; j < searchFieldLen; j++)
|
||||||
{
|
{
|
||||||
printf("%c", salad[i][j]);
|
printf("%c", salad[i][j]);//Ausgabe des Arrays auf die Konsole
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -9,27 +9,27 @@
|
|||||||
// 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 zeile[MAX_LINE_LEN];
|
char zeile[MAX_LINE_LEN];
|
||||||
char* teiler = ".;, ";
|
char* teiler = ".;, "; //Trennung zwischen den Wörtern einer Zeile
|
||||||
int wordCount = 0;
|
int wordCount = 0;
|
||||||
char* token;
|
char* token; // Einzelwort aus Zeile
|
||||||
while(fgets(zeile, MAX_LINE_LEN, file)!=NULL)
|
while(fgets(zeile, MAX_LINE_LEN, file)!=NULL) //Zeilenweises einlesen
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_LINE_LEN; i++)
|
for (int i = 0; i < MAX_LINE_LEN; i++)
|
||||||
{
|
{
|
||||||
if (zeile[i] >= 'a'&&zeile[i] <= 'z')
|
if (zeile[i] >= 'a'&&zeile[i] <= 'z') //Ersetzen aller Kleinbuchstaben in Großbuchstaben
|
||||||
{
|
{
|
||||||
zeile[i]=zeile[i]-32;
|
zeile[i]=zeile[i]-32; //ASCII-Code -32 entspricht dem jeweiligen Großbuchstaben
|
||||||
}
|
}
|
||||||
if (zeile[i] == '\n')
|
if (zeile[i] == '\n')
|
||||||
{
|
{
|
||||||
zeile[i] = '\0';
|
zeile[i] = '\0'; //Ende der Zeile = String Ende
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = strtok(zeile,teiler);
|
token = strtok(zeile,teiler);
|
||||||
while(token != NULL && wordCount <= maxWordCount)
|
while(token != NULL && wordCount < maxWordCount)
|
||||||
{
|
{
|
||||||
strcpy(words[wordCount],token);
|
strcpy(words[wordCount],token);//Trennen der Wörter in einer Zeile und kopieren in 2D Array "untereinander"
|
||||||
token = strtok(NULL,teiler);
|
token = strtok(NULL,teiler);
|
||||||
wordCount++;
|
wordCount++;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
[33mcommit e58f113c46c1af49c3680b6da5cc999b56b0093a[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mmain[m[33m, [m[1;31morigin/main[m[33m, [m[1;31morigin/HEAD[m[33m)[m
|
|
||||||
Author: Kruschat <max.kruschat@siemens.com>
|
|
||||||
Date: Thu Oct 23 14:55:49 2025 +0200
|
|
||||||
|
|
||||||
Test geändert
|
|
||||||
|
|
||||||
[33mcommit 89ca3acc38758a65a28a874ceda5d3253c1cb6d8[m
|
|
||||||
Author: Bannach <kevin.bannach@siemens.com>
|
|
||||||
Date: Thu Oct 23 14:54:03 2025 +0200
|
|
||||||
|
|
||||||
Testdatei
|
|
||||||
|
|
||||||
[33mcommit 15db90e12e6413714750ac23a78aa369bf192a22[m
|
|
||||||
Author: Bannach <kevin.bannach@siemens.com>
|
|
||||||
Date: Thu Oct 23 14:52:08 2025 +0200
|
|
||||||
|
|
||||||
Testdatei aktualisiert
|
|
||||||
|
|
||||||
[33mcommit b804c4264c21980ba6497fb76da0da6151c1b9ed[m
|
|
||||||
Author: Bannach <kevin.bannach@siemens.com>
|
|
||||||
Date: Wed Oct 22 20:57:00 2025 +0200
|
|
||||||
|
|
||||||
Textdatei Test hinzugefügt
|
|
||||||
|
|
||||||
[33mcommit 496e4d82e75945b8899aa012e0039034f40a1db1[m
|
|
||||||
Author: Kevin Bannach <bannachke98909@th-nuernberg.de>
|
|
||||||
Date: Wed Oct 22 07:21:52 2025 +0000
|
|
||||||
|
|
||||||
Initial commit
|
|
||||||
Loading…
x
Reference in New Issue
Block a user