first implementation for input
This commit is contained in:
1 parent
dc58f1e4a9
commit
aef73683bc
11 files changed
+58
-39
No files matched your search
+42
-1
@@ -6,7 +6,48 @@
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
// printf("start readWords\n");
|
||||
int wordcount = 0;
|
||||
char line[256];
|
||||
char *lines = fgets(line, sizeof(line), file);
|
||||
|
||||
}
|
||||
while(lines != NULL)
|
||||
{
|
||||
// printf("next line: %s\n", lines);
|
||||
size_t wordLength = 0;
|
||||
int newWord = 0;
|
||||
|
||||
for(int i = 0; i < strlen(lines); i++)
|
||||
{
|
||||
//printf("size of line %d: %d\n", i, strlen(lines));
|
||||
if(isalpha(line[i]))
|
||||
{
|
||||
words[wordcount][wordLength] = line[i];
|
||||
// printf("word[%d][%d] = %c\n", wordcount, wordLength, line[i]);
|
||||
|
||||
wordLength += 1;
|
||||
newWord = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(newWord == 0)
|
||||
{
|
||||
// printf("skip: %c\n", line[i]);
|
||||
wordcount += 1;
|
||||
wordLength = 0;
|
||||
newWord = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("Multi skip: %c\n", line[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
lines = fgets(line, sizeof(line), file);
|
||||
}
|
||||
// printf("wordcount = %d\n", wordcount);
|
||||
return wordcount;
|
||||
}
|
||||
Reference in new issue
Block a user