Compare commits
No commits in common. "96917cc4e98ea18b8571596a2699deebc9c82909" and "0ee04e2b9e0bec99a27820a5f5125aae71bc2b80" have entirely different histories.
96917cc4e9
...
0ee04e2b9e
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,7 +7,4 @@ graphicalGame.o
|
||||
wordsalad
|
||||
wordsalad_initial.exe
|
||||
runTests.exe
|
||||
testwords_delims.txt
|
||||
testwords_empty.txt
|
||||
testwords_simple.txt
|
||||
.vscode
|
||||
@ -1,5 +1,4 @@
|
||||
#include "input.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@ -7,39 +6,7 @@
|
||||
// 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
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_WORD_LEN];
|
||||
unsigned int count = 0;
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL)
|
||||
{
|
||||
// Zerlege Zeile in einzelne Wörter anhand der Trennzeichen
|
||||
char *token = strtok(buffer, " ,;\n");
|
||||
while (token != NULL && count < maxWordCount)
|
||||
{
|
||||
// In Großbuchstaben umwandeln
|
||||
for (int i = 0; token[i] != '\0'; i++)
|
||||
{
|
||||
token[i] = toupper((unsigned char)token[i]);
|
||||
}
|
||||
|
||||
// Token in das words-Array kopieren
|
||||
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren
|
||||
|
||||
count++;
|
||||
|
||||
// Nächsten Token holen
|
||||
token = strtok(NULL, " ,;\n");
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
#include "input.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@ -7,39 +6,7 @@
|
||||
// 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
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_WORD_LEN];
|
||||
unsigned int count = 0;
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL)
|
||||
{
|
||||
// Zerlege Zeile in einzelne Wörter anhand der Trennzeichen
|
||||
char *token = strtok(buffer, " ,;\n");
|
||||
while (token != NULL && count < maxWordCount)
|
||||
{
|
||||
// In Großbuchstaben umwandeln
|
||||
for (int i = 0; token[i] != '\0'; i++)
|
||||
{
|
||||
token[i] = toupper((unsigned char)token[i]);
|
||||
}
|
||||
|
||||
// Token in das words-Array kopieren
|
||||
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren
|
||||
|
||||
count++;
|
||||
|
||||
// Nächsten Token holen
|
||||
token = strtok(NULL, " ,;\n");
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user