Files
info2Praktikum-Wortsalat/Startcode/input.c
T
2026-10-29 16:25:50 +01:00

34 lines
793 B
C

#include "input.h"
#include <ctype.h>
#include <string.h>
void toUpperCase(char *word);
unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char buffer[MAX_LINE_LEN];
unsigned int count = 0;
char *divisor = " ,;.\n";
while (fgets(buffer, MAX_LINE_LEN, file) != NULL)
{
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
{
strncpy(words[count], word, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0';
toUpperCase(words[count]);
++count;
}
}
return count;
}
void toUpperCase(char *word)
{
for (int i = 0; i < strlen(word); ++i)
{
word[i] = toupper(word[i]);
}
}