Compare commits

..

No commits in common. "84de10d05bfba2a323277b6d4397a8024bc8d073" and "eb77a4d1b87d6f3324e50a982ebba3bb23602b85" have entirely different histories.

7 changed files with 16 additions and 38 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
static char *buffer; #define MAX_BUFFER_LEN 256
// 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.
@ -10,51 +10,29 @@ static char *buffer;
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
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; char buffer[MAX_BUFFER_LEN];
int word = 0; int count = 0;
int wordChar = 0; char *teiler = ".,; !?\n";
int firstLetter = 0;
if (file == NULL) if(file == NULL)
{ {
return 0; printf("Fehler beim Öffnen von words.txt!\n");
return -1;
} }
fscanf(file, "%10s", buffer);
do while(fgets(buffer, MAX_LINE_LEN, file))
{ {
const char *wort = strtok(buffer, teiler);
if ((buffer[i] >= 'A') && (buffer[i] <= 'Z')) while(wort != NULL && count < maxWordCount)
{ {
if (!firstLetter) strncpy(words[count], wort, MAX_WORD_LEN-1);
{ words[count][MAX_WORD_LEN-1] = '\0';
firstLetter = 1; count++;
}
words[word][wordChar] = buffer[i];
wordChar++;
}
else if ((buffer[i] >= 'a') && (buffer[i] <= 'z'))
{
if (!firstLetter)
{
firstLetter = 1;
}
words[word][wordChar] = toupper(buffer[i]); wort = strtok(NULL, teiler);
wordChar++;
}
else if (firstLetter)
{
words[word][wordChar] = '\0';
word++;
wordChar = 0;
firstLetter = 0;
} }
}
i++; return count;
} while ((i < MAX_LINE_LEN) && (word < maxWordCount));
return word+1;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.