generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
No commits in common. "4fea2c9f7b08a31823487efb3d6e4796df92ad92" and "19787739a748d59ac37519f7dd6f59b8bcd8b98a" have entirely different histories.
4fea2c9f7b
...
19787739a7
@ -8,25 +8,37 @@
|
|||||||
// 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
|
||||||
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
// MAX_LINE_LEN 1024
|
||||||
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
// *file ist Datei
|
||||||
int i;
|
// 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;
|
||||||
|
|
||||||
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
||||||
{
|
{
|
||||||
char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
|
char *parts = strtok(puffer, ",;\n\t/. ");
|
||||||
|
|
||||||
while(word_parts != NULL && counter < maxWordCount)
|
while(parts != NULL && counter < maxWordCount)
|
||||||
{
|
{
|
||||||
for(i = 0; i < MAX_WORD_LEN -1 && word_parts[i] != '\0'; i++)
|
//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++)
|
||||||
{
|
{
|
||||||
words[counter][i] = toupper(word_parts[i]); //Großbuchstaben erzeugen
|
words[counter][i] = toupper(parts[i]);
|
||||||
|
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
|
||||||
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
|
parts = strtok(NULL, ",;\n\t/. ");
|
||||||
|
|
||||||
}
|
}
|
||||||
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