Compare commits
2
Commits
manu
...
30c53ce8b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30c53ce8b9 | ||
|
|
61c60ebffd |
+15
-17
@@ -8,27 +8,25 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
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[MAX_LINE_LEN];
|
char puffer[MAX_WORD_LEN];
|
||||||
char *teiler = " ,;\n";
|
char *teiler = " ,;";
|
||||||
char *token;
|
char *token;
|
||||||
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen
|
fgets(puffer, MAX_LINE_LEN, file);
|
||||||
|
|
||||||
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde
|
token = strtok(puffer, teiler);
|
||||||
|
|
||||||
|
while(token != NULL && wordCount < maxWordCount)
|
||||||
{
|
{
|
||||||
return -1;
|
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
|
||||||
|
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
wordCount++;
|
||||||
|
|
||||||
|
token =strtok(NULL, teiler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fgets(puffer, MAX_LINE_LEN, words_txt_speicherort); //speichert alle Zeichen der words.txt datei in den speicher
|
return wordCount;
|
||||||
|
|
||||||
token = strtok(puffer, teiler); //Trennt das erste Wort der Zeichenkette, abhängig von den Teilerbedingungen
|
|
||||||
|
|
||||||
while(token != NULL)
|
|
||||||
|
|
||||||
words = token; //speichert nur das einzelne Word in das words array; Problem: Laufindex der global gespeichert werden müsste; wie springe ich beim 2ten Funktionsaufruf zum nächsten Wort
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int fclose(words_txt_speicherort);
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user