generated from freudenreichan/info2Praktikum-Wortsalat
Mein Branch gemacht
This commit is contained in:
1 parent
bc1c053b2f
commit
b8dbcee641
2 files changed
+51
-1
No files matched your search
@@ -5,8 +5,49 @@
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Erkennen der Trennzeichen -> c = 1 wenn Trennzeichen
|
||||
// Static ist interne Hilfsfunktion, die auserhalb nicht aufgerufen werden kann
|
||||
static int istTrennzeichen (int c)
|
||||
{
|
||||
return c == ' ' || c == ',' || c == ';' || c == '\n' || c == '\t'|| c == '\r';
|
||||
}
|
||||
|
||||
|
||||
static int readWord(FILE *file, char *word)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
int c = fgetc(file);
|
||||
|
||||
// Trennzeichen vor Wort überspringen (EOF= End of File)
|
||||
while(c != EOF && istTrennzeichen(c))
|
||||
{
|
||||
c = fgetc(file);
|
||||
}
|
||||
|
||||
//Buchstaben sammeln bis Trennzeichen oder Dateiende
|
||||
while(c != EOF && !istTrennzeichen(c))
|
||||
{
|
||||
if(len < MAX_WORD_LEN -1)
|
||||
{
|
||||
word[len] = toupper(c);
|
||||
len++;
|
||||
}
|
||||
c = fgetc(file);
|
||||
}
|
||||
|
||||
word[len] = '\0';
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
while(count < maxWordCount && readWord(file, words[count]))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
+10
-1
@@ -41,10 +41,19 @@ int main(int argc, char *argv[])
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
if(placedWords == wordCount)
|
||||
{
|
||||
//600 Pixel random gewählt, Keine daten dazu gefunden;
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 600);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Not all words could be placed ...\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user