This commit is contained in:
Tobias Busch 2025-11-02 21:28:15 +01:00
parent b07cf08f26
commit 9a7d3d3766

View File

@ -8,7 +8,49 @@
// 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)
{ {
FILE *fopen (const char *file, const char *r); // != NULL??? unsigned int count = 0;
fclose(*file ); char line[MAX_LINE_LEN];
char *teiler = " ,;";
char *token;
while(fgets(line, sizeof(line), file)){
//Yeti,Nessie Werwolf; Vampir
// token = Yeti
token = strtok(line, teiler);
while (token != NULL)
{
if (strlen(token) >= MAX_WORD_LEN) {
printf("Fehler: eigelesenes Wort ist zu lang\n");
return count;
}
if (count >= maxWordCount){
printf("Fehler: zu viele Wörter\n");
return count;
}
strncpy(words[count], token, MAX_WORD_LEN-1);
words[count][MAX_WORD_LEN-1] = '\0';
//Nessie Werwolf; Vampir
//token= Nessie
token = strtok(NULL, teiler);
count++;
}
}
return count;
} }
// 00M 01a 02x
// 10W 11a 12l 13t 14e 15r
// 20T 21o 22b 23i 24a 25s
// array[3][2]
// 00 01
// 10 11
// 20 21