Einlesefunktion hinzugefügt
This commit is contained in:
Generated
+1
-7
@@ -1,8 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="CPP_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
||||
+23
-1
@@ -1,6 +1,7 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
@@ -8,5 +9,26 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
|
||||
char zeile[MAX_LINE_LEN];
|
||||
char* teiler = ".;, ";
|
||||
int wordCount = 0;
|
||||
char* token;
|
||||
printf("Datei geöffnet\n");
|
||||
while(fgets(zeile, MAX_LINE_LEN, file)!=NULL)
|
||||
{
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (zeile[i] == '\n') {
|
||||
zeile[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
token = strtok(zeile,teiler);
|
||||
while(token != NULL)
|
||||
{
|
||||
strcpy(words[wordCount],token);
|
||||
token = strtok(NULL,teiler);
|
||||
wordCount++;
|
||||
}
|
||||
}
|
||||
return wordCount;
|
||||
}
|
||||
Reference in New Issue
Block a user