Erste Versuche input.c zu implementieren
This commit is contained in:
1 parent
18b1d1ca72
commit
0686dcc2fe
2 files changed
+23
-1
No files matched your search
@@ -8,5 +8,27 @@
|
||||
// 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 *token;
|
||||
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei
|
||||
|
||||
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen
|
||||
|
||||
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde
|
||||
{
|
||||
return -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)
|
||||
|
||||
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);
|
||||
}
|
||||
+1
-1
@@ -6,6 +6,6 @@
|
||||
#define MAX_WORD_LEN 100
|
||||
#define MAX_LINE_LEN 1024
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user