fürs erste fertige input.c datei (hoffentlich)
This commit is contained in:
parent
bda3c2b104
commit
1ca4567185
@ -6,24 +6,23 @@
|
||||
// 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)
|
||||
{
|
||||
|
||||
char puffer[MAX_WORD_LEN];
|
||||
file = fopen("words.txt", "r");
|
||||
if (file == NULL)
|
||||
{
|
||||
perror("File couldn't be opened");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char fehlerhafterString[MAX_LINE_LEN];
|
||||
char *teiler = " ;,.\n";
|
||||
char teiler[] = " ;,.\n";
|
||||
char *aktuellesWort;
|
||||
int wortAnzahl = 0;
|
||||
|
||||
while (fgets(fehlerhafterString, sizeof(fehlerhafterString), file) != NULL && wortAnzahl < maxWordCount)
|
||||
while (fgets(puffer, MAX_WORD_LEN, file) != NULL)
|
||||
{
|
||||
|
||||
aktuellesWort = strtok(fehlerhafterString, teiler);
|
||||
aktuellesWort = strtok(puffer, teiler);
|
||||
|
||||
while (aktuellesWort != NULL && wortAnzahl < maxWordCount)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user