input.c errors behoben

This commit is contained in:
fischerch103508 committed 2026-10-13 20:33:40 +02:00
1 parent 61c60ebffd
commit 30c53ce8b9
1 file changed
+14 -13
+14 -13
View File
@@ -8,24 +8,25 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char puffer[MAX_WORD_LEN];
char *teiler = " ,;";
char *token;
unsigned int counter =0;
unsigned int wordCount = 0;
token = strtok(file, teiler);
counter += 1;
strncpy(words, token, MAX_WORD_LEN);
token = strtok(NULL, teiler);
counter += 1;
fgets(puffer, MAX_LINE_LEN, file);
while(token != NULL)
token = strtok(puffer, teiler);
while(token != NULL && wordCount < maxWordCount)
{
stncat(words, token, MAX_WORD_LEN);
token = strtok(NULL, teiler);
counter += 1;
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
token =strtok(NULL, teiler);
}
return counter;
return wordCount;
}