Merge pull request 'Start_Windows/input.c aktualisiert' (#2) from version_noah into main
Reviewed-on: #2
This commit is contained in:
commit
526c042273
@ -9,4 +9,32 @@
|
|||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
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