forked from freudenreichan/info2Praktikum-Wortsalat
Polish
This commit is contained in:
4 files changed
+23
-11
No files matched your search
+6
-5
@@ -13,7 +13,7 @@ int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN]
|
|||||||
int searchFieldLen, int column, int row, int axis);
|
int searchFieldLen, int column, int row, int axis);
|
||||||
|
|
||||||
// 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(
|
unsigned int createWordSalad(
|
||||||
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||||
unsigned int searchFieldLen,
|
unsigned int searchFieldLen,
|
||||||
const char words[][MAX_WORD_LEN],
|
const char words[][MAX_WORD_LEN],
|
||||||
@@ -41,9 +41,9 @@ int createWordSalad(
|
|||||||
// Wörter platzieren
|
// Wörter platzieren
|
||||||
for (int w = 0; w < wordCount; w++)
|
for (int w = 0; w < wordCount; w++)
|
||||||
{
|
{
|
||||||
int wordlenght = strlen(words[w]); // Wortlänge festgelegt
|
int wordlength = strlen(words[w]); // Wortlänge festgelegt
|
||||||
|
|
||||||
if (wordlenght == 0 || wordlenght > searchFieldLen)
|
if (wordlength == 0 || wordlength > searchFieldLen)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ int createWordSalad(
|
|||||||
int row = rand() % searchFieldLen;
|
int row = rand() % searchFieldLen;
|
||||||
int column = rand() % searchFieldLen;
|
int column = rand() % searchFieldLen;
|
||||||
|
|
||||||
int success = placeWord(words[w], wordlenght, salad, searchFieldLen, column, row, axis);
|
int success = placeWord(words[w], wordlength, salad, searchFieldLen, column, row, axis);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,8 @@ int createWordSalad(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%d placed", placedWords);
|
|
||||||
|
printf("%d placed\n", placedWords);
|
||||||
return placedWords;
|
return placedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
#define MAX_SEARCH_FIELD_LEN 100
|
#define MAX_SEARCH_FIELD_LEN 100
|
||||||
|
|
||||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
unsigned int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+15
-4
@@ -1,22 +1,33 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count);
|
void toUpperCase(char *word);
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
char buffer[MAX_LINE_LEN];
|
char buffer[MAX_LINE_LEN];
|
||||||
int count = 0;
|
unsigned int count = 0;
|
||||||
char *divisor = " ,;.\n";
|
char *divisor = " ,;.\n";
|
||||||
|
|
||||||
while (fgets(buffer, MAX_LINE_LEN, file) != NULL)
|
while (fgets(buffer, MAX_LINE_LEN, file) != NULL)
|
||||||
{
|
{
|
||||||
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
|
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
|
||||||
{
|
{
|
||||||
strncpy(words[count], word, MAX_WORD_LEN);
|
strncpy(words[count], word, MAX_WORD_LEN - 1);
|
||||||
|
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
toUpperCase(words[count]);
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toUpperCase(char *word)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strlen(word); ++i)
|
||||||
|
{
|
||||||
|
word[i] = toupper(word[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -6,6 +6,6 @@
|
|||||||
#define MAX_WORD_LEN 100
|
#define MAX_WORD_LEN 100
|
||||||
#define MAX_LINE_LEN 1024
|
#define MAX_LINE_LEN 1024
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user