generated from freudenreichan/info2Praktikum-Wortsalat
input bugfix
This commit is contained in:
parent
19787739a7
commit
817f35a154
@ -8,37 +8,25 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
// MAX_WORD_LEN 100
|
||||
// MAX_LINE_LEN 1024
|
||||
// *file ist Datei
|
||||
// words ist Array
|
||||
// MAX_WORD_LEN ist maximale Wortlänge
|
||||
// maxWordCount ist maximale Anzahl an Wörtern
|
||||
char puffer[MAX_LINE_LEN];
|
||||
int counter = 0;
|
||||
|
||||
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
||||
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
||||
int i;
|
||||
|
||||
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
||||
{
|
||||
char *parts = strtok(puffer, ",;\n\t/. ");
|
||||
char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
|
||||
|
||||
while(parts != NULL && counter < maxWordCount)
|
||||
while(word_parts != NULL && counter < maxWordCount)
|
||||
{
|
||||
//strncpy(words[counter][MAX_WORD_LEN], puffer, MAX_LINE_LEN-1);
|
||||
//words[counter][MAX_WORD_LEN-1] = "\0";
|
||||
//Großbuchstaben
|
||||
for(int i = 0; i < MAX_WORD_LEN -1 && parts[i] != '\0'; i++)
|
||||
for(i = 0; i < MAX_WORD_LEN -1 && word_parts[i] != '\0'; i++)
|
||||
{
|
||||
words[counter][i] = toupper(parts[i]);
|
||||
words[counter][i] = '\0';
|
||||
words[counter][i] = toupper(word_parts[i]); //Großbuchstaben erzeugen
|
||||
}
|
||||
words[counter][i] = '\0'; //Stringdefinition vervollständigen
|
||||
}
|
||||
counter++; // Wort eingelesen -> Wortzähler erhöhen
|
||||
parts = strtok(NULL, ",;\n\t/. ");
|
||||
|
||||
counter++; // Wort eingelesen, Wortzähler erhöhen
|
||||
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TODO: Wörter auf Zahlen, Umlaute überprüfen -> ändern
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user