Merge branch 'my-changes' of https://git.efi.th-nuernberg.de/gitea/shobayoeniolasi99076/info2Praktikum-ES into my-changes
This commit is contained in:
commit
4c5e903057
@ -25,6 +25,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Platzieren der Wörter
|
// Platzieren der Wörter
|
||||||
|
unsigned int placedWords = 0;
|
||||||
for (unsigned int w = 0; w < wordCount; ++w) {
|
for (unsigned int w = 0; w < wordCount; ++w) {
|
||||||
const char *word = words[w];
|
const char *word = words[w];
|
||||||
size_t wordLen = strlen(word);
|
size_t wordLen = strlen(word);
|
||||||
@ -34,7 +35,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
|
|
||||||
int placed = 0;
|
int placed = 0;
|
||||||
for (int attempts = 0; attempts < MAX_RAND_TRIES_PER_WORD && !placed; ++attempts) {
|
for (int attempts = 0; attempts < MAX_RAND_TRIES_PER_WORD && !placed; ++attempts) {
|
||||||
int vertical = rand() % 2; // 0=horizontal, 1=vertical
|
int vertical = rand() % 2; // 0=horizontal, 1=vertikal
|
||||||
unsigned int row, col;
|
unsigned int row, col;
|
||||||
|
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
@ -69,9 +70,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
placed = 1;
|
placed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!placed) {
|
if (placed) {
|
||||||
// Ein Wort konnte nicht platziert werden, Abbruch möglich
|
placedWords++;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return placedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
|
|||||||
@ -12,19 +12,23 @@ char* readWord(FILE *file)
|
|||||||
int c; // Variable für jedes gelesene Zeichen
|
int c; // Variable für jedes gelesene Zeichen
|
||||||
|
|
||||||
// Whitespace und Delimiters überspringen
|
// Whitespace und Delimiters überspringen
|
||||||
while((c = fgetc(file)) != EOF && (isspace(c) || c == ',' || c == ';' || c == '.'));
|
while ((c = fgetc(file)) != EOF && (isspace((unsigned char)c) || c == ',' || c == ';' || c == '.'));
|
||||||
|
|
||||||
|
if (c == EOF) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Buchstaben einlesen bis nächstes whitespace/Delimiter/EOF
|
// Buchstaben einlesen bis nächstes whitespace/Delimiter/EOF
|
||||||
while(c != EOF && !isspace(c) && c != ',' && c != ';' && c != '.' && index < MAX_WORD_LEN - 1) //-1 wegen Nullterminator
|
while (c != EOF && !isspace((unsigned char)c) && c != ',' && c != ';' && c != '.' && index < MAX_WORD_LEN - 1) //-1 wegen Nullterminator
|
||||||
{
|
{
|
||||||
word[index++] = (char)toupper(c); // Konvertiere zu Großbuchstaben
|
word[index++] = (char)toupper((unsigned char)c); // Konvertiere zu Großbuchstaben
|
||||||
c = fgetc(file);
|
c = fgetc(file);
|
||||||
}
|
}
|
||||||
word[index] = '\0'; // Nullterminator (= Ende String)
|
word[index] = '\0'; // Nullterminator (= Ende String)
|
||||||
|
|
||||||
// Leere überspringen
|
if (index == 0) {
|
||||||
if(index == 0)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return strdup(word); // Rückgabe string, dynamisch allokiert da Zeiger auf lokalen Puffer zurückgegeben
|
return strdup(word); // Rückgabe string, dynamisch allokiert da Zeiger auf lokalen Puffer zurückgegeben
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user