generated from freudenreichan/info2Praktikum-Wortsalat
Anpassungen main.c und input.c in Start_Mac
This commit is contained in:
parent
a5c1510745
commit
5442ecb0bc
@ -2,11 +2,37 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define MAX_BUFFER_LEN 256
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// 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_BUFFER_LEN];
|
||||||
|
int count = 0;
|
||||||
|
char *teiler = ".,; !?\n";
|
||||||
|
|
||||||
|
if(file == NULL)
|
||||||
|
{
|
||||||
|
printf("Fehler beim Öffnen von words.txt!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(fgets(buffer, MAX_LINE_LEN, file))
|
||||||
|
{
|
||||||
|
const char *wort = strtok(buffer, teiler);
|
||||||
|
|
||||||
|
while(wort != NULL && count < maxWordCount)
|
||||||
|
{
|
||||||
|
strncpy(words[count], wort, MAX_WORD_LEN-1);
|
||||||
|
words[count][MAX_WORD_LEN-1] = '\0';
|
||||||
|
count++;
|
||||||
|
|
||||||
|
wort = strtok(NULL, teiler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
@ -7,6 +7,13 @@
|
|||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
|
|
||||||
|
// selbstgeschriebene Definitionen:
|
||||||
|
// annahmen ist das windowWidth in pixeln gegeben
|
||||||
|
// werden muss, da auch andere funktionen wie
|
||||||
|
// createCharSquarePanel in Pixeln arbeiten
|
||||||
|
#define WINDOW_WIDTH 800
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
@ -36,10 +43,24 @@ 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:
|
// DONE:
|
||||||
// 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)
|
||||||
|
{
|
||||||
|
// selbe error message wird auch von wordsalad_inital.exe ausgegeben,
|
||||||
|
// wenn diese einen fehler produziert
|
||||||
|
printf("Could only place %d of %d words.", placedWords, wordCount);
|
||||||
|
printf(" Possible solution is to choose a larger search field ...\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// annahme: windowWidth wird in Pixeln gesucht,
|
||||||
|
// da auch andere funktionen, wie createCharSquarePanel
|
||||||
|
// in Pixeln arbeiten
|
||||||
|
startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user