input angepasst
This commit is contained in:
1 parent
59f222f3c1
commit
61c60ebffd
1 file changed
+14
-17
+14
-17
@@ -8,27 +8,24 @@
|
|||||||
// 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 *teiler = " ,;\n";
|
char *teiler = " ,;";
|
||||||
char *token;
|
char *token;
|
||||||
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei
|
unsigned int counter =0;
|
||||||
|
|
||||||
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen
|
token = strtok(file, teiler);
|
||||||
|
counter += 1;
|
||||||
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde
|
strncpy(words, token, MAX_WORD_LEN);
|
||||||
{
|
token = strtok(NULL, teiler);
|
||||||
return -1;
|
counter += 1;
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
while(token != NULL)
|
||||||
|
{
|
||||||
|
stncat(words, token, MAX_WORD_LEN);
|
||||||
|
token = strtok(NULL, teiler);
|
||||||
|
counter += 1;
|
||||||
|
|
||||||
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
|
}
|
||||||
|
|
||||||
|
return counter;
|
||||||
|
|
||||||
int fclose(words_txt_speicherort);
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user