Compare commits

...

2 Commits

Author SHA1 Message Date
Björn
0c086b9607 input verbessert 2025-10-26 18:41:44 +01:00
Björn
b88cf94072 miau 2025-10-26 18:30:29 +01:00
3 changed files with 21 additions and 17 deletions

BIN
Start_Windows/Test.exe Normal file

Binary file not shown.

View File

@ -8,21 +8,29 @@
// 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)
{ {
if (file == NULL) { char line[1024]; // Puffer für eine Zeile
printf("Datei konnte nicht geoffnet werden");
return 0;
}
// 2D char Array um wörter zu speichern
char word[MAX_WORD_LEN];
unsigned int count = 0; unsigned int count = 0;
while (fscanf(file, "%s", word) != EOF && count < maxWordCount) {
// Kopiere das gelesene Wort in das 2D-Array // Alle gewünschten Trennzeichen
strncpy(words[count], word, MAX_WORD_LEN - 1); const char *delimiters = " \t\n,.;:!?\"'()[]{}";
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist
count++; while (fgets(line, sizeof(line), file) && count < maxWordCount) {
char *token = strtok(line, delimiters);
while (token != NULL && count < maxWordCount) {
// Alles in Großbuchstaben umwandeln
for (int i = 0; token[i]; i++) {
token[i] = toupper(token[i]);
} }
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung
count++;
token = strtok(NULL, delimiters);
}
}
fclose(file); fclose(file);
return count; return count;
} }

View File

@ -1,5 +1 @@
Yeti,Nessie Werwolf; Vampir test
Monster
Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger