6 Commits
Author SHA1 Message Date
lukas 51e9f406fd Implemented parsing on delimiters in input.c 2026-10-28 10:23:24 +01:00
lukas a290fba480 Merge branch 'gade' into baeuml 2026-10-28 09:12:00 +01:00
lukas b76c87a19e Merge branch 'mueller' into baeuml 2026-10-28 09:11:06 +01:00
Baeuml 783bb755e9 TODO in main.c implementiert 2026-10-28 00:02:26 +01:00
Gade 1cb18630be Input Aufgaben bearbeitet 2026-10-27 21:51:27 +01:00
Gade 24466628da main.c ohne //a 2026-10-27 21:47:10 +01:00
2 changed files with 54 additions and 3 deletions

No files matched your search

+41
View File
@@ -1,6 +1,19 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
#define DELIM_COUNT 4
int find_delim(const char* line, char delim_list[DELIM_COUNT]){
int i = 0;
while(line[i] != '\n'){
for(int j = 0; j < DELIM_COUNT; j++){
if(line[i] == delim_list[j])
return i;
}
i++;
}
return i;
}
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
@@ -8,5 +21,33 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char line[MAX_LINE_LEN];
int count = 0;
int word_end = 0;
int word_start = 0;
char delim_list[DELIM_COUNT] = {'\n', ';', ',', ' '};
while (fgets(line, MAX_LINE_LEN, file) != NULL &&
count < maxWordCount)
{
word_end = 0;
word_start = 0;
while(line[word_start ? word_start - 1 : 0] != '\n' && count < maxWordCount){
word_end = find_delim(line + word_start, delim_list);
// Wort ins Array kopieren
if(word_end) {
strncpy(words[count], line + word_start, word_end);
words[count][word_end] = '\0';
// In Großbuchstaben umwandeln
for (int i = 0; words[count][i] != '\0'; i++)
{
words[count][i] = toupper((unsigned char)words[count][i]);
}
count++;
}
word_start += word_end + 1;
}
}
return count;
}
+13 -3
View File
@@ -10,7 +10,7 @@
int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
//a
// Check if the correct number of arguments is provided
if(argc != 2)
{
@@ -37,9 +37,19 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount)
{
// Start the game if successful
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else
{
// error message if some words couldn't be placed
fprintf(stderr, "Error: Only %u of %u words could be placed.\n", placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
}
else