Großbuchstaben einlesen
This commit is contained in:
parent
8d94db8e56
commit
e2747c285f
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,9 @@
|
|||||||
I2_Wortsalat/Start_Mac/wordsalad_initial
|
I2_Wortsalat/Start_Mac/wordsalad_initial
|
||||||
I2_Wortsalat/Start_Mac/.DS_Store
|
I2_Wortsalat/Start_Mac/.DS_Store
|
||||||
I2_Wortsalat/.DS_Store
|
I2_Wortsalat/.DS_Store
|
||||||
|
I2_Wortsalat/Start_Mac/input.o
|
||||||
|
.gitignore
|
||||||
|
I2_Wortsalat/Start_Mac/game.o
|
||||||
|
I2_Wortsalat/Start_Mac/runTests
|
||||||
|
.o
|
||||||
|
.a
|
||||||
@ -8,13 +8,15 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
char lines [1024]; //TODO: Sinnvolle Begrenzung finden
|
char lines [(MAX_WORD_LEN + 2) * maxWordCount]; //Es wird davon ausgegangen, dass die Wörter nur durch eine Trennzeichen und ein Leerzeichen von einander gertrennt gespeichert werden
|
||||||
int word_counter = 0;
|
int word_counter = 0;
|
||||||
|
|
||||||
while (fgets(lines, sizeof(lines) , file) != NULL)
|
while (fgets(lines, sizeof(lines) , file) != NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; lines[i] != '\0'; i++) //Entfernen von \n aus dem String
|
for (int i = 0; lines[i] != '\0'; i++) //Entfernen von \n aus dem String
|
||||||
{
|
{
|
||||||
|
lines[i] = toupper(lines[i]);
|
||||||
if (lines[i] == '\n')
|
if (lines[i] == '\n')
|
||||||
{
|
{
|
||||||
lines[i] = '\0';
|
lines[i] = '\0';
|
||||||
@ -26,12 +28,16 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
|
|
||||||
while (single_word != NULL && word_counter < maxWordCount)
|
while (single_word != NULL && word_counter < maxWordCount)
|
||||||
{
|
{
|
||||||
|
|
||||||
strncpy(words[word_counter], single_word, MAX_WORD_LEN - 1);
|
strncpy(words[word_counter], single_word, MAX_WORD_LEN - 1);
|
||||||
words [word_counter][MAX_WORD_LEN -1] = '\0'; //Zur Sicherheit, damit \0 auf alle Fälle vorhanden ist
|
words [word_counter][MAX_WORD_LEN -1] = '\0'; //Zur Sicherheit, damit \0 auf alle Fälle vorhanden ist
|
||||||
word_counter++;
|
word_counter++;
|
||||||
single_word = strtok(NULL, " ;,");
|
single_word = strtok(NULL, " ;,");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return word_counter;
|
return word_counter;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user