generated from freudenreichan/info2Praktikum-Wortsalat
input.c fertig 2 und game.c ins terminal geprintet
This commit is contained in:
parent
d5539e08b8
commit
ef907a5662
@ -62,5 +62,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
printf("WORTSALAT:\n\n");
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
for (int j = 0; j < searchFieldLen; j++) {
|
||||
printf("%c ", salad[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,11 +12,24 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
char text [2000];
|
||||
char line[200];
|
||||
int i = 0;
|
||||
int textcount = 0;
|
||||
int counter = 0;
|
||||
char *token;
|
||||
|
||||
|
||||
while (fgets(line, sizeof(line), ptr)) {
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
|
||||
for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) {
|
||||
text[i++] = line[j];
|
||||
textcount++;
|
||||
if (textcount>1999) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (textcount>1999) {
|
||||
|
||||
printf("Textdatei zugross!!!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,25 +42,25 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
const char *trenner = ",; \n";
|
||||
token = strtok(text, trenner);
|
||||
|
||||
while (token != NULL) {
|
||||
while (token != NULL&& counter < maxWordCount) {
|
||||
|
||||
|
||||
|
||||
strncpy(words[zaehler], token, MAX_WORD_LEN - 1);
|
||||
words[zaehler][MAX_WORD_LEN - 1] = '\0';
|
||||
strncpy(words[counter], token, MAX_WORD_LEN - 1);
|
||||
words[counter][MAX_WORD_LEN - 1] = '\0';
|
||||
token = strtok(NULL, trenner);
|
||||
|
||||
|
||||
zaehler++;
|
||||
counter++;
|
||||
}
|
||||
maxWordCount=zaehler;
|
||||
|
||||
|
||||
|
||||
//alle Buchstaben in Großbuchstaben ändern
|
||||
|
||||
|
||||
|
||||
for (int h = 0; h < zaehler; h++) {
|
||||
for (int h = 0; h < counter; h++) {
|
||||
for (int check = 0; words[h][check] != '\0'; check++) {
|
||||
if (words[h][check] >= 'a' && words[h][check] <= 'z') {
|
||||
words[h][check] -= 32; // direkt ins Array schreiben
|
||||
@ -56,5 +69,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return counter;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user