game.c implementiert

This commit is contained in:
fischerch103508 committed 2026-10-17 15:26:06 +02:00
1 parent 356bb5cb9e
commit a5e963f2a6
3 files changed
+112 -21

No files matched your search

+16 -21
View File
@@ -8,36 +8,31 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char puffer[MAX_LINE_NUMBER][MAX_LINE_LEN];
char puffer[MAX_LINE_LEN];
char *teiler = "\n ,;";
char *token;
int i = 0;
unsigned int wordCount = 0;
while(fgets(puffer[i], MAX_LINE_LEN, file) != NULL)
while(fgets(puffer, MAX_LINE_LEN, file) != NULL) //Liest die zeilenweise Wörter aus der file in einen Zwischenpuffer bis das Dateiende erreicht ist returnwert der file == NULL
{
i++;
}
token = strtok(puffer, teiler); // Holt sich per Teilerbedingung das erste Wort aus dem puffer
i = 0;
token = strtok(puffer[i], teiler);
while(token != NULL && wordCount < maxWordCount)
{
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
//words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
token = strtok(NULL, teiler);
if(token == NULL && i < MAX_LINE_NUMBER)
while(token != NULL && wordCount < maxWordCount)
{
token = strtok(puffer[i+1], teiler);
}
for(int i = 0; i < MAX_WORD_LEN; i++) //Verwandelt jeden Buchstaben in einen Großbuchstaben
{
token[i] = toupper(token[i]);
}
strncpy(words[wordCount], token, MAX_WORD_LEN -1); //speichert einzelnes Wort in das gegeben word array ab und holt sich das nächste im Puffer, bis array leer token == NULL
//words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
token = strtok(NULL, teiler);
}
}
return wordCount;
}