finish wordsalad

- remove printf for debugging and add startGame to main.c
This commit is contained in:
hoangto105860 committed 2026-10-27 16:59:33 +01:00
1 parent cbf5f85caf
commit 596e0a5519
7 files changed
+8 -35

No files matched your search

+1 -23
View File
@@ -15,30 +15,15 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{
unsigned int placedWords = 0;
//printf("start game.c\n");
emptyField(searchFieldLen, salad);
for(int i = 0; i < wordCount; i++)
{
placedWords += placement(salad, searchFieldLen, words[i]);
//printf("[%d] of words: %s\n", i, words[i]);
}
fillRandAlpha(searchFieldLen, salad);
printf("placedWords:%d\n", placedWords);
for(int i = 0; i < searchFieldLen; i++)
{
for(int j = 0; j < searchFieldLen; j++)
{
printf("%c", salad[j][i]);
}
printf("\n");
}
return placedWords;
}
@@ -57,8 +42,6 @@ int placement(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned i
int saladX = rand() % ( searchFieldLen - strlen(word) );
int saladY = rand() % ( searchFieldLen - strlen(word) );
printf("%s\n", word);
if(rand() % 2)
{
for(int i = 0; i < strlen(word); i++)
@@ -100,11 +83,8 @@ void emptyField(unsigned int searchFieldLen, char salad[MAX_SEARCH_FIELD_LEN][MA
{
for(size_t j = 0; j < searchFieldLen; j++)
{
//salad[i][j] = '\0';
salad[i][j] = ' ';
printf("%c", salad[i][j]);
salad[i][j] = '\0';
}
printf("\n");
}
}
@@ -117,10 +97,8 @@ char fillRandAlpha(unsigned int searchFieldLen, char salad[MAX_SEARCH_FIELD_LEN]
if(!isalpha(salad[i][j]))
{
salad[i][j] = alphaRand();
//printf("%c", salad[i][j]);
}
}
printf("\n");
}
return 0;
}
BIN
View File
Binary file not shown.
+1 -10
View File
@@ -11,22 +11,18 @@
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
printf("start readWords\n");
int wordcount = 0;
char buffer[256];
char *line = fgets(buffer, sizeof(buffer), file);
while(line != NULL)
{
printf("%d. loop\n", wordcount);
printf("line: %s\n", line);
char* word = strtok(line, " ,;");
while (word != NULL)
{
strncpy(words[wordcount], word, strlen(word));
//printf("%d. word: %s\n", wordcount, words[wordcount]);
wordcount += 1;
word = strtok(NULL, " ,;\t\n");
@@ -46,12 +42,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
words[i][j] = '\0';
}
}
printf("%d. word: %s\n", i, words[i]);
}
printf("wordcount = %d\n", wordcount);
return wordcount;
}
BIN
View File
Binary file not shown.
+6 -2
View File
@@ -14,8 +14,8 @@ int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
printf("start main\n");
srand(time(NULL));
// Check if the correct number of arguments is provided
if(argc != 2)
{
@@ -51,13 +51,17 @@ int main(int argc, char *argv[])
{
// Start the game if successful
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
return exitCode;
}
}
// error message if some words couldn't be placed
fprintf(stderr, "could not start wordsalad.\n");
fprintf(stderr, "Could not start wordsalad. ");
printf("Out of %d words only %d could be placed.\n", wordCount, placedWords);
puts("GOOD LUCK for getting this game started :)");
exitCode = EXIT_FAILURE;
}
else
BIN
View File
Binary file not shown.
Binary file not shown.