generated from freudenreichan/info2Praktikum-Wortsalat
input passes all tests
This commit is contained in:
parent
46b6efbd69
commit
7414849901
@ -2,8 +2,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
static char *buffer;
|
|
||||||
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||||
@ -27,20 +25,49 @@ char *readSingleWord(FILE *file)
|
|||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int numberOfReadWords = 0;
|
int firstLetter = 0;
|
||||||
|
int word = 0;
|
||||||
|
int wordChar = 0;
|
||||||
char currentChar = 0;
|
char currentChar = 0;
|
||||||
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
fgetc(file + i);
|
currentChar = fgetc(file);
|
||||||
|
|
||||||
|
if ((currentChar >= 'A') && (currentChar <= 'Z'))
|
||||||
|
{
|
||||||
|
if (!firstLetter)
|
||||||
|
{
|
||||||
|
firstLetter = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
words[word][wordChar] = currentChar;
|
||||||
|
wordChar++;
|
||||||
|
}
|
||||||
|
else if ((currentChar >= 'a') && (currentChar <= 'z'))
|
||||||
|
{
|
||||||
|
if (!firstLetter)
|
||||||
|
{
|
||||||
|
firstLetter = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
words[word][wordChar] = toupper(currentChar);
|
||||||
|
wordChar++;
|
||||||
|
}
|
||||||
|
else if (firstLetter)
|
||||||
|
{
|
||||||
|
words[word][wordChar] = '\0';
|
||||||
|
word++;
|
||||||
|
wordChar = 0;
|
||||||
|
firstLetter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
} while (currentChar != EOF);
|
} while ((currentChar != EOF) && (word < maxWordCount));
|
||||||
|
|
||||||
|
|
||||||
|
return word;
|
||||||
return numberOfReadWords;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user