generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
2 Commits
19787739a7
...
4fea2c9f7b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fea2c9f7b | ||
|
|
817f35a154 |
@ -8,37 +8,25 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
// MAX_WORD_LEN 100
|
|
||||||
// MAX_LINE_LEN 1024
|
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
||||||
// *file ist Datei
|
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
||||||
// words ist Array
|
int i;
|
||||||
// MAX_WORD_LEN ist maximale Wortlänge
|
|
||||||
// maxWordCount ist maximale Anzahl an Wörtern
|
|
||||||
char puffer[MAX_LINE_LEN];
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
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);
|
for(i = 0; i < MAX_WORD_LEN -1 && word_parts[i] != '\0'; i++)
|
||||||
//words[counter][MAX_WORD_LEN-1] = "\0";
|
|
||||||
//Großbuchstaben
|
|
||||||
for(int i = 0; i < MAX_WORD_LEN -1 && parts[i] != '\0'; i++)
|
|
||||||
{
|
{
|
||||||
words[counter][i] = toupper(parts[i]);
|
words[counter][i] = toupper(word_parts[i]); //Großbuchstaben erzeugen
|
||||||
words[counter][i] = '\0';
|
|
||||||
}
|
}
|
||||||
|
words[counter][i] = '\0'; //Stringdefinition vervollständigen
|
||||||
}
|
}
|
||||||
counter++; // Wort eingelesen -> Wortzähler erhöhen
|
counter++; // Wort eingelesen, Wortzähler erhöhen
|
||||||
parts = strtok(NULL, ",;\n\t/. ");
|
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
|
||||||
|
|
||||||
}
|
}
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: Wörter auf Zahlen, Umlaute überprüfen -> ändern
|
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user