generated from freudenreichan/info2Praktikum-Wortsalat
Merge pull request 'Feat/input' (#1) from feat/input into main
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
commit
d77fd52f7d
3 files changed
+69
-2
No files matched your search
+43
-2
@@ -1,12 +1,53 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
// 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)
|
static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||||
{
|
|
||||||
|
|
||||||
|
unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
{
|
||||||
|
int wordCount = 0;
|
||||||
|
char lineRead[MAX_LINE_LEN];
|
||||||
|
|
||||||
|
while(fgets(lineRead, MAX_LINE_LEN, file) != NULL && wordCount < (int)maxWordCount)
|
||||||
|
{
|
||||||
|
wordCount += createSingleWords(lineRead, words + wordCount, maxWordCount - wordCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wordCount; //wordCount
|
||||||
|
}
|
||||||
|
|
||||||
|
static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
{
|
||||||
|
char *teiler = " ;,.\n";
|
||||||
|
char *token;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
token = strtok(text, teiler);
|
||||||
|
|
||||||
|
while(token != NULL && i < maxWordCount)
|
||||||
|
{
|
||||||
|
strncpy(words[i], token, MAX_WORD_LEN - 1);
|
||||||
|
//kleinbuchstaben --> GROßBUCHSTABEN
|
||||||
|
int length = strlen(words[i]);
|
||||||
|
for(int j = 0; j < length; j++)
|
||||||
|
{
|
||||||
|
if(islower(words[i][j]))
|
||||||
|
{
|
||||||
|
words[i][j] = toupper(words[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
words[i][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
token = strtok(NULL, teiler);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,23 @@ int main(int argc, char *argv[])
|
|||||||
// 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(wordCount > 19)
|
||||||
|
{
|
||||||
|
if(placedWords != 20)
|
||||||
|
{
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
printf("Only %d of %d possible words could be placed\n", placedWords, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(placedWords != wordCount)
|
||||||
|
{
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
printf("Only %d of %d possible words could be placed\n", placedWords, wordCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ codefolder = .
|
|||||||
wordsalad_initial:
|
wordsalad_initial:
|
||||||
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Zwischenstände
|
||||||
|
# --------------------------
|
||||||
|
wordsalad_mymain: main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_mymain main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
wordsalad_myinput: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_myinput input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user