Start_Windows/input.c aktualisiert
Die Funktion wurde vervollständigt. Noch auf Funktionalität überprüfen.
This commit is contained in:
parent
dbbda468bf
commit
96b421fd22
@ -9,4 +9,32 @@
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
|
||||
char puffer[256];
|
||||
char *teiler = " ,;.\n";
|
||||
char *token;
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
/* wird words.txt schon in main geöffnet?
|
||||
file = fopen ("words.txt", "r"); // Öffne words.txt zum lesen
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
while (fgets (puffer, 256, file) != NULL) //liest words.txt ein und speichert es in puffer
|
||||
{
|
||||
token = strtok(puffer, teiler); //token teilt erstes Wort und speichert es in sich ab
|
||||
|
||||
while (token != NULL && wordCount < maxWordCount)
|
||||
{
|
||||
strncpy(words[wordCount], token, MAX_WORD_LEN -1); //kopiert das Wort von token in das array words
|
||||
words[wordCount][MAX_WORD_LEN-1] = '\0';
|
||||
wordCount++;
|
||||
token = strtok (NULL, teiler); //nächstes Wort
|
||||
}
|
||||
}
|
||||
|
||||
return wordCount; //Anzahl der gelesenen Wörter
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user