Compare commits
2
Commits
chris2
...
30c53ce8b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30c53ce8b9 | ||
|
|
61c60ebffd |
+15
-17
@@ -8,27 +8,25 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char puffer[MAX_LINE_LEN];
|
||||
char *teiler = " ,;\n";
|
||||
char puffer[MAX_WORD_LEN];
|
||||
char *teiler = " ,;";
|
||||
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
|
||||
|
||||
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);
|
||||
return wordCount;
|
||||
}
|
||||
Reference in new issue
Block a user