generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
4 Commits
543ba65b7e
...
7414849901
| Author | SHA1 | Date | |
|---|---|---|---|
| 7414849901 | |||
| 46b6efbd69 | |||
| 1affb13041 | |||
| 63cafdbc0c |
@ -2,6 +2,77 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||||
|
|
||||||
|
/*
|
||||||
|
char *readSingleWord(FILE *file)
|
||||||
|
{
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fgets(singleWordBuffer, MAX_LINE_LEN, file);
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Read words from file and store in 'words' array
|
||||||
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int firstLetter = 0;
|
||||||
|
int word = 0;
|
||||||
|
int wordChar = 0;
|
||||||
|
char currentChar = 0;
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
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++;
|
||||||
|
} while ((currentChar != EOF) && (word < maxWordCount));
|
||||||
|
|
||||||
|
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
#define MAX_BUFFER_LEN 256
|
#define MAX_BUFFER_LEN 256
|
||||||
|
|
||||||
// TODO?
|
// TODO?
|
||||||
@ -36,3 +107,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user