input.c fertig
This commit is contained in:
parent
0feb82646e
commit
1f3236c18b
@ -8,5 +8,32 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
|
||||
unsigned int count = 0;
|
||||
char line[512];
|
||||
|
||||
// Lese Datei zeilenweise
|
||||
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount)
|
||||
{
|
||||
// Zerlege die Zeile in Tokens (Wörter), getrennt durch gängige Delimiter
|
||||
char *token = strtok(line, " ,;:.!?\"\n\r\t");
|
||||
|
||||
while (token != NULL && count < maxWordCount)
|
||||
{
|
||||
// In Großbuchstaben umwandeln
|
||||
for (int i = 0; token[i]; i++)
|
||||
token[i] = toupper((unsigned char)token[i]);
|
||||
|
||||
// Wort kopieren
|
||||
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||
|
||||
count++;
|
||||
token = strtok(NULL, " ,;:.!?\"\n\r\t");
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user